I'm a beginner in R and I would like to know how to do the following task:
I want to replace the missing values of my dataset by the median for all the columns of my dataset. However, for each column, I want the median of a certain category (depending on another column).My dataset is as follows
structure(list(Country = structure(1:5, .Label = c("Afghanistan",
"Albania", "Algeria", "Andorra", "Angola"), class = "factor"),
CountryID = 1:5, Continent = c(1L, 2L, 3L, 2L, 3L), Adolescent.fertility.rate.... = c(151L,
27L, 6L, NA, 146L), Adult.literacy.rate.... = c(28, 98.7,
69.9, NA, 67.4)), class = "data.frame", row.names = c(NA,
-5L))
So for each of the columns, I want to replace the missing values by the median of the values in the specific continent.