Hello,

Print DateTime, and see what's wrong.

When you paste(), you use the order ymd HM with space as separator but when you try to convert to POSIXct you pass a wrong format, not the one created by paste().

Solution: as.POSIXct(DAteTime, format="%Y %m %d %H %M")

Hope this helps,

Rui Barradas

Em 17-07-2012 15:48, Yolande Tra escreveu:
  I was wondering why I get <NA> instead of the timestamp in the following.
Thanks.

dataDir <- file.path(wd)
localRaw <- read.csv(file.path(dataDir,"LOCAL.csv"), as.is=T,stringsAsFactors
= FALSE)
localRaw[1:2,]
   Year Month Day hour minute second Temp1mab Temp7mab Temp14mab Salinity1mab
1 2009    10   5    0      0      0   11.288   13.675    13.743       33.513
2 2009    10   5    0     15      0   11.258   13.684    13.716       33.514
   O21mab waveht wavedir waveperiod depth mab along across
1      0 54.926   1.600        340  9.09   .    NA     NA
2      0 55.574   1.525        340  9.09   .    NA     NA
DateTime<-with(localRaw,paste(Year,Month,Day,hour,minute))
DateTime<-as.POSIXct(DateTime, format="%m/%d/%Y %H:%M")
localCond_2009<-xts(localRaw ,order.by=DateTime)
localCond_2009[1:2,]
      Year   Month Day  hour minute second Temp1mab Temp7mab Temp14mab
<NA> "2009" "10"  " 5" " 0" " 0"   "0"    "11.288" "13.675" "13.743"
<NA> "2009" "10"  " 5" " 0" "15"   "0"    "11.258" "13.684" "13.716"
      Salinity1mab O21mab waveht   wavedir waveperiod depth    mab along
across
<NA> "33.513"     "0"    "54.926" "1.600" "340.0"    " 9.090" "." NA
NA
<NA> "33.514"     "0"    "55.574" "1.525" "340.0"    " 9.090" "." NA
NA

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


______________________________________________
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