----- Forwarded Message -----
From: arun <[email protected]>
To: Ye Lin <[email protected]>
Cc:
Sent: Friday, April 12, 2013 6:25 PM
Subject: Re: [R] split date and time
Hi Ye,
Is this okay?
dat2<-cbind(dat1[,-2],do.call(rbind,strsplit(dat1[,2],"
")),stringsAsFactors=FALSE)
dat2
# Number Value 1 2
#1 1 1 1/1/2013 0:00
#2 2 2 1/1/2013 0:01
#3 3 3 1/1/2013 0:03
colnames(dat2)[3:4]<- c("Date","Time")
dat2
# Number Value Date Time
#1 1 1 1/1/2013 0:00
#2 2 2 1/1/2013 0:01
#3 3 3 1/1/2013 0:03
str(dat2)
#'data.frame': 3 obs. of 4 variables:
#$ Number: int 1 2 3
#$ Value : int 1 2 3
#$ Date : chr "1/1/2013" "1/1/2013" "1/1/2013"
#$ Time : chr "0:00" "0:01" "0:03"
________________________________
From: Ye Lin <[email protected]>
To: arun <[email protected]>
Sent: Friday, April 12, 2013 6:16 PM
Subject: Re: [R] split date and time
What if I have many columns, for example I have 50 columns in dat1, and say the
"TimeStamp" column is the 10th, anyway to do that instead of listing all the
other columns when building dat2?
Thanks!
On Fri, Apr 12, 2013 at 3:08 PM, arun <[email protected]> wrote:
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 <[email protected]>
>To: R help <[email protected]>
>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]]
>
>______________________________________________
>[email protected] 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.
>
>
______________________________________________
[email protected] 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.