Skip to content

NA instead of time stamp

4 messages · Yolande Tra, John Kane, arun +1 more

#
I think that you need to supply some data with your question.  

Use dput() to output your data or a subset of it and paste the output into the email
See ?dput for more information.

Probably a subset of the data would be sufficient.  Something like
dput(head(localRaw, 50) should be fine.




John Kane
Kingston ON Canada
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
#
Hello,

I think there is some mistake in the format.

Try this:


dat1<-data.frame(Year=rep(2009,2),Month=rep(10,2),Day=rep(5,2),hour=rep(0,2),minute=c(0,15),second=c(11.288,11.258))

###Your code

?DateTime<-with(dat1,paste(Year,Month,Day,hour,minute))

DateTime
#[1] "2009 10 5 0 0"? "2009 10 5 0 15"

?DateTime1<-as.POSIXct(DateTime,format="%m/%d/Y %H:%M")
?DateTime1
#[1] NA NA


######Corrected one

DateTime<-with(dat1,paste(Year,Month,Day,hour,minute,sep="/"))
?DateTime1<-as.POSIXct(DateTime,format="%Y/%m/%d/%H/%M")

?DateTime1
#[1] "2009-10-05 00:00:00 EDT" "2009-10-05 00:15:00 EDT"
?

A.K.




----- Original Message -----
From: Yolande Tra <yolande.tra at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, July 17, 2012 10:48 AM
Subject: [R] NA instead of time stamp

I was wondering why I get <NA> instead of the timestamp in the following.
Thanks.
= FALSE)
? 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
? ?  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 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.
#
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: