Re: [R] replace non numeric with "NA"

From: Nandini B <nandini_bn_at_hotmail.com>
Date: Fri, 29 Apr 2011 21:04:23 +0530

Thanks a lot Duncan, this is what I was looking for!!Thank you,Nandini

> Date: Fri, 29 Apr 2011 09:53:06 -0400
> From: murdoch.duncan_at_gmail.com
> To: nandini_bn@hotmail.com
> CC: r-help_at_r-project.org
> Subject: Re: [R] replace non numeric with "NA"
>
> On 29/04/2011 6:45 AM, Nandini B wrote:
> > Hello,
> > I have a sample data frame which looks like this
> > day od month
> > 1 1 0.1 2
> > 2 3 #VALUE! 1
> > 3 5 0.4 12
> > 4 7 0.8 10
> > 5 11 - 3
> > 6 14 s 7
> > 7 18 -- 12
> > 8 27 19 7
> >
> >
> > Now i wish to filter all the non numeric values and replace it with "NA". The data frame is actually huge and the non numeric characters vary from "-" to a string to absolutely anything!!!
> > Can anyone please help ?
>
> You don't tell use the types of the columns, so I'll assume they are
> factors. If so, call
>
> as.numeric(as.character())
>
> on each of them to convert the number-like values to numbers, the others
> to NA. For example,
>
> df$day <- as.numeric(as.character(df$day))
>
> Duncan Murdoch
                                               

        [[alternative HTML version deleted]]



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. Received on Fri 29 Apr 2011 - 19:07:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 29 Apr 2011 - 19:10:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive