[R] NA problem
David Winsemius
dwinsemius at comcast.net
Tue Sep 21 14:33:28 CEST 2010
On Sep 21, 2010, at 5:28 AM, Jeff Newmiller wrote:
> Short answer: don't do that.
>
> The format function is for preparing data for output. Do your data
> manipulations on a data frame you keep for such use, and only use
> format to prepare for output.
That is excellent advice. But to answer the question for the situation
where the problem is less global, or in which the person were
determined to press on....
To substitute "." for NA then the is.na function is needed:
> cvec <-c("1", "2 400.3", NA)
> cvec[is.na(cvec)] <- "."
Note(s):
"NA" is not NA, and nothing ever, ever "=="'s NA
> is.na(NA)
[1] TRUE
> is.na("NA")
[1] FALSE
> NA == NA
[1] NA
> NA == "NA"
[1] NA
--
David.
>
> "n.vialma at libero.it" <n.vialma at libero.it> wrote:
>
>> Dear R list
>> I have a problem with NA, which should be a string, but R seems
>> that it
>> doesn't recognize it. What I do is first give the format command
>> to my data
>> frame:
>>
>> format.data.frame(mydata,big.mark=" ")
>>
>> so I give a blank as thousand separator. All my records in my data
>> frame
>> become strings, so instead of having NA I have "NA". I try to
>> convert "NA" in
>> ".",but it seems that R doesn't recognize "NA".
>>
>> Someone knows why and how to treats those "NA"??
>>
>>
>> Thanks for your attention
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go
> Live...
> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#.
> Live Go...
> Live: OO#.. Dead: OO#..
> Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#.
> rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list