[R] data.frame with NA

Berend Hasselman bhh at xs4all.nl
Mon Mar 18 18:46:07 CET 2013


On 18-03-2013, at 16:49, Pete <freerisk3 at gmail.com> wrote:

> 
> I have this little data.frame
> 
> http://dl.dropbox.com/u/102669/nanotna.rdata
> 
> Two column contains NA, so the best thing to do is use na.locf function (with
> fromLast = T)
> 
> But locf function doesn't work because NA in my data.frame are not recognized as
> real NA.
> 
> Is there a way to substitute fake NA with real NA? In this case na.locf function
> should work
> 

Your data are all characters. Do

str(db)

to see that. What is probably supposed to be numeric is also character,
Somehow you have managed to read in data that R thinks is all chr.
Your NA are "NA" in reality: a character string "NA".

You will have to review the method you used to get the data into R.
And make sure that what you want to be numeric is indeed numeric.
Then you can start to think about doing something about the NA's.

Berend



More information about the R-help mailing list