I have data frame with column names 1990.x ..2000.x, 1990.y,..2000.y. I want to replace NAs in variables ending with ".x" with values from .y from corresponding year. It is element by element computation of formula 1990.x = 0.5+0.2*log(1990.y)
I wanted to do something like this:
for (v in colnames(df[ ,grepl(".x",names(df))])) {
print(v)
df$v <- ifelse(is.na(df$v), ols$coefficients[1]+ols$coefficients[2]*log(df$gsub(".x",".y",v)), df$v)
}
but this is not working. How can i make this loop working, or is there any better solution? Thanks