Skip to content

split date and time

2 messages · Ye Lin, arun

#
Hi,
dat1<- read.table(text="
Number,TimeStamp,Value
1,1/1/2013 0:00,1
2,1/1/2013 0:01,2
3,1/1/2013 0:03,3
",sep=",",header=TRUE,stringsAsFactors=FALSE)
dat2<-data.frame(Number=dat1[,1],do.call(rbind,strsplit(dat1[,2]," ")), Value=dat1[,3])
?names(dat2)[2:3]<- c("Date","Time")
?dat2
#? Number???? Date Time Value
#1????? 1 1/1/2013 0:00???? 1
#2????? 2 1/1/2013 0:01???? 2
#3????? 3 1/1/2013 0:03???? 3
A.K.




----- Original Message -----
From: Ye Lin <yelin at lbl.gov>
To: R help <r-help at r-project.org>
Cc: 
Sent: Friday, April 12, 2013 5:49 PM
Subject: [R] split date and time

Hi R experts,

For example I have a dataset looks like this:


Number?  TimeStamp?  Value
1? ? ? ? ? ? ? 1/1/2013 0:00 1
2 1/1/2013 0:01 2
3 1/1/2013 0:03 3

How can I split the "TimeStamp" Column into two and return a new table like
this:

Number?  Date? ? ? ? ?  Time?  Value
1? ? ? ? ? ? ?  1/1/2013 0:00 1
2 1/1/2013 0:01 2
3 1/1/2013 0:03 3

Thank!

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