[R] Help: problem converting character to numeric
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Mar 14 23:32:37 CET 2012
On Wed, Mar 14, 2012 at 6:07 PM, Aurélien PHILIPPOT
<aurelien.philippot at gmail.com> wrote:
> Dear R experts,
> I have a dataframe imported from a csv file (with read.csv).
>
> Here is an example:
>
> yyyymm<- c("19860228", "19860331","19860430","19860531")
> id<-c("10000","10000","10000","10000")
> re<- c("C","0.25", "0.98", "1.34")
>
> mret<-data.frame(yyyymm, id, re)
>
> mret<-as.numeric(as.character(mret$re))
> Error: (converted from warning) NAs introduced by coercion
>
Check the value of the warn option:
> getOption("warn")
[1] 0
> as.numeric("C") # ok just gives warning
[1] NA
Warning message:
NAs introduced by coercion
> options(warn = 2)
> as.numeric("C") # now its an error
Error: (converted from warning) NAs introduced by coercion
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list