[R] NA problem

peter dalgaard pdalgd at gmail.com
Tue Sep 21 11:51:31 CEST 2010


On Sep 21, 2010, at 11:28 , 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.

But isn't that what the OP is doing? It is actually a bit odd that the formatting functions  do not allow the NA code to be set. Probably, the easiest workaround goes like this

aqf <- format(airquality)
aqf[is.na(airquality)] <- "-"
head(aqf)

  Ozone Solar.R Wind Temp Month Day
1    41     190  7.4   67     5   1
2    36     118  8.0   72     5   2
3    12     149 12.6   74     5   3
4    18     313 11.5   62     5   4
5     -       - 14.3   56     5   5
6    28       - 14.9   66     5   6



> 
> "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.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list