From: Mark Myatt (email@example.com)
Date: Wed 09 May 2001 - 20:20:15 EST
Jean Vidal <firstname.lastname@example.org> writes:
>I'm discovering R (very impressive), and didn't find in the docs a simple
>method for replacing, in a data frame, missing values (NA) with the
>column's mean (or any other method for reconstructing missing values when
>Thanks in advance for your help.
There are a series of na.* Functions in R but they are not well
documented (which is my way of saying "I can't work out how to make them
I use indexing to deal with missing values. For example:
var[var == -99] <- NA
To replace a missing value code (e.g. -99) with NA. Replacing with an
imputed value can be done in the same manner but with the imputation
function on the RHS of the assignment. For example:
var[is.na(var)] <- mean(var, na.rm = TRUE)
If var is a vector in a data.frame then you need to specify the
df$var[is.na(df$var)] <- mean(df$var, na.rm = TRUE)
I hope that helps.
BTW: While I am here, can anyone explain how the na.* functions work?
-- Mark Myatt
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: email@example.com _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This archive was generated by hypermail 2b30 : Fri 22 Jun 2001 - 18:58:41 EST