I'm trying to fill some missing values for rows that meet certain conditions from another column. My data is given below. For China for the years 2002 and 2003, I want to copy values from the column named "manu_GDP_old" into the column "manu_GDP". In other words, I'm trying to fill the missing values of "manu_GDP" for China from the column "manu_GDP_old".
I would ideally like to do this using the dplyr package.
Thanks in advance.
df <- structure(list(country = c("Brazil", "Brazil", "Brazil", "Brazil",
"Brazil", "China", "China", "China", "China", "China"), year = c(2002,
2003, 2004, 2005, 2006, 2002, 2003, 2004, 2005, 2006), manu_GDP = c(12.3569626659174,
14.4507645634139, 15.0995301566951, 14.7382811350657, 14.108945871671,
NA, NA, 31.9750699702633, 32.0939243286777, 32.4523280565943),
manu_GDP_old = c(NA, NA, NA, NA, NA, "31.1", "32.5", "32.0",
"32.1", "32.5")), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))