Thanks. It was very helpful.
Y

On Sun, Jul 29, 2012 at 2:45 AM, arun <smartpink...@yahoo.com> wrote:

> Hello,
>
> I tried to do the same thing that you have done.  Without the timestamps
> as rownames (xts object), there were no errors.
>
> dat1<-read.table(text="
> dive_id  date        time      species        count size
>  1 08/06/2008 8:49:00 S.OYT        15 6
>
>  1 08/06/2008 8:49:00 S.atrovirens 1 23
> ",header=TRUE, sep="")
>  dat2<-dat1
> saveRDS(dat2,"dat2.rds")
>  dat3<-readRDS("dat2.rds")
>  str(dat3)
> #'data.frame':    2 obs. of  6 variables:
> # $ dive_id: int  1 1
> # $ date   : Factor w/ 1 level "08/06/2008": 1 1
> # $ time   : Factor w/ 1 level "8:49:00": 1 1
> # $ species: Factor w/ 2 levels "S.atrovirens",..: 2 1
> # $ count  : int  15 1
> # $ size   : int  6 23
> dat3$count<-as.numeric(dat3$count)
>  is.numeric(dat3$count)
> #[1] TRUE
>
> ####Now with timestamps as row.names
> library(xts)
>
>  DateTime<-as.POSIXct(c("2008-08-06 08:49:00","2008-08-06
> 08:49:00"),format="%Y-%m-%d %H:%M")
> dat4<-xts(dat1,order.by=DateTime)
>  saveRDS(dat4,"dat4.rds")
>  dat5<-readRDS("dat4.rds")
>  identical(dat4,dat5)
> #[1] TRUE
> dat5$count<-as.numeric(dat5$count)
> #Here, I didn't get the warning message that you got
> > is.numeric(dat5$count)
> #[1] FALSE
> #So, I assume that it is not because of reading the file as an RDS
> extension, but reading it as an xts object.
> #You can convert the xts to dataframe and do the conversion of "count"
> column to numeric.
> dat6<-data.frame(date=index(dat5),coredata(dat5))
>
>
>  str(dat6)
> #'data.frame':    2 obs. of  7 variables:
>  #$ date   : POSIXct, format: "2008-08-06 08:49:00" "2008-08-06 08:49:00"
>  #$ dive_id: Factor w/ 1 level "1": 1 1
>  #$ date.1 : Factor w/ 1 level "08/06/2008": 1 1
>  #$ time   : Factor w/ 1 level "8:49:00": 1 1
>  #$ species: Factor w/ 2 levels "S.atrovirens",..: 2 1
>  #$ count  : Factor w/ 2 levels " 1","15": 2 1
>  #$ size   : Factor w/ 2 levels "23"," 6": 2 1
>  dat6$count<-as.numeric(dat6$count)
>  is.numeric(dat6$count)
> #[1] TRUE
> I hope this helps.
>
> A.K.
>
>
>
>
>
>
>
> ----- Original Message -----
> From: Yolande Tra <yolande....@gmail.com>
> To: R help <r-help@r-project.org>
> Cc:
> Sent: Saturday, July 28, 2012 10:23 PM
> Subject: [R] readRDS, In as.double.xts(fishReport$count) : NAs introduced
> by coercion
>
> Hello,
>
> I looked in the R-help but could not find an archive addressing the
> following. I would like to convert a character to numeric after reading a
> file with RDS extension. After using as.numeric, I checked if it is
> numeric. It was not converted. Please help.
>
> Here is my code
>
> >Report <- readRDS(file="RDS/Report.RDS")
> > Report[1:2,]
>                     dive_id date         time      species         count
> size
> 2008-08-06 08:49:00 " 1"    "08/06/2008" "8:49:00" "S. OYT"        "15"
> "6"
> 2008-08-06 08:49:00 " 1"    "08/06/2008" "8:49:00" "S. atrovirens" "1"
> "23"
>                     site      depth level TRANSECT VIS_M TEMP_C swell_URSKI
> 2008-08-06 08:49:00 "Hopkins" "15"  "B"   "1"      "3.5" "13.9" "1.0686708"
> 2008-08-06 08:49:00 "Hopkins" "15"  "B"   "1"      "3.5" "13.9" "1.0686708"
> > Report$count<-as.numeric(Report$count)
> Warning message:
> In as.double.xts(fishReport$count) : NAs introduced by coercion
> >is.numeric(Report$count)
> [1] FALSE
> Thank you,
> Y
>
>     [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to