[R] how to remove "." or replace it with NA?

John Fox jfox at mcmaster.ca
Sun May 30 22:35:15 CEST 2004


Dear Spenser et al.,

sed stands for "string editor," I believe, and it is a Unix utility,
although there are implementations for other OS's including Windows.

For Yong Wang's problem, I think that it is more natural to use the
na.strings argument to read.table(), as I previously suggested, than to edit
the data file.

Regards,
 John

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Spencer Graves
> Sent: Sunday, May 30, 2004 11:23 AM
> To: Yong Wang
> Cc: r-help at stat.math.ethz.ch; Samir Mishra
> Subject: Re: [R] how to remove "." or replace it with NA?
> 
>       It's apparently a unix command;  www.r-project.org -> 
> search -> "R site search" -> sed produced at least one hit 
> with the following example: 
> 
> scan(pipe("sed -e s/,$// data2"), sep=",")
> 
>       For the rest of this comment, see the R site search.  
> hope this helps.  spencer graves
> 
> Yong Wang wrote:
> 
> >Samir, can you give an example for the use of sed?
> >
> >
> >
> >On Sun, 30 May 2004, Samir Mishra wrote:
> >
> >  
> >
> >>If the data file is in text format, is large with a lot of 
> "."s, use sed.
> >>It's MUCH faster than any other tool for this sort of thing.
> >>
> >>-----Original Message-----
> >>From: Yong Wang [mailto:wang at galton.uchicago.edu]
> >>Sent: Sunday, May 30, 2004 05:25
> >>To: r-help at stat.math.ethz.ch
> >>Subject: [R] how to remove "." or replace it with NA?
> >>
> >>
> >>Hi,all
> >>a quick question
> >>A larger file include many"." (stands for missing
> >>value) for variable, say, x. after
> >>read in the file and assign it another name such as :
> >>
> >>x1<-data$x
> >>
> >>but x1 is always a facotor but not numerical. 
> >>
> >>so How can I get a numeric vector from the read in data frame.
> >>how can I replace those "." with "NA" to perform analysis.
> >>
> >>thank you very much
> >>best regards
> >>
> >>______________________________________________
> >>R-help at stat.math.ethz.ch mailing list
> >>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >>PLEASE do read the posting guide!
> >>http://www.R-project.org/posting-guide.html
> >>
> >>    
> >>
> >
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide! 
> >http://www.R-project.org/posting-guide.html
> >  
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list