Dear All,
Replacing missing values with means is generally not a good idea:
"Perhaps the easiest way to impute is to replace each missing
value with the mean of the observed values for that variable. Unfortunately,
this
strategy can severely distort the distribution for this variable, leading t
Apologies, I re-read the question and realised you hope to replace the missing
values rounded to the nearest whole number.
Here’s the code in full.
df1 <- data.frame(x = c(25, 30, 40, 26, 60), y = c(122, 135, NA, 157, 195), z =
c(352, 376, 350, NA, 360))
means <- sapply(df1, mean, na.rm = T);
Hi Val,
You could do this by nesting 2 for loops, and defining a function such that it
returns the mean of the column when the value is ‘NA’.
df1 <- data.frame(x = c(25, 30, 40, 26, 60), y = c(122, 135, NA, 157, 195), z =
c(352, 376, 350, NA, 360)); df2 <- df1[0, ]
means <- sapply(df1, mean, n
3 matches
Mail list logo