[R-sig-ME] Missing data in R...

Ben Bolker bbolker at gmail.com
Fri Feb 18 17:36:03 CET 2011


On 11-02-18 11:32 AM, Jeffrey Harring wrote:
> I am reading in data in the "long" format into R to use in nlme ( ).
> There is some missing data that is denoted by a period "."
> I would like to assign these .'s the missing data value NA. I have been
> unable to locate code on the web that might perform this function.
> 
> This is what I have thus far:   dat1[dat1$y == ".", "y"] <- NA
> 
> where the data are assigned to data frame dat1 and the missing data is
> in a variable called y.
> 
> If anyone has a suggestion I am all ears.
> 
> Thanks,
> Jeff
> 
> 

  see the 'na.strings' argument in ?read.table (also applies to read.csv)
  the problem is that having the '.' in there in the first place will
make your numeric variables turn into factors -- you can deal with this via

dat1$y <- as.numeric(as.character(dat1$y))

which will make anything that can't be interpreted as numeric into an NA
(and issue a warning) but it is easier and clearer to specify na.strings
in the first place.

  For what it's worth, you might ask these kinds of questions on the
general R-help list -- they are not specific to mixed models.  (Make
sure to read the Posting Guide first ...)




More information about the R-sig-mixed-models mailing list