On Thu, May 9, 2013 at 8:09 PM, Gabor Grothendieck
<ggrothendi...@gmail.com> wrote:
> On Thu, May 9, 2013 at 7:24 PM, Ye Lin <ye...@lbl.gov> wrote:
>> Hey All,
>>
>> I want to duplicate the records but add a new "timestamp" columns as new
>> time series, but I dont know how to do that.
>>
>> my dataset(dat1) looks like this:
>>
>> No.          TimeStamp          Var1
>>
>> 1         2012-06-18 06:00:00    3
>> 2         2012-06-18 06:06:00     4
>>
>> I use this code to do duplication:
>>
>> dat1[rep(1:nrow(dat1),each=3),]
>>
>> But I dont know how to change the timeStamp. I would like the final output
>> be sth like this:
>>
>> No.          TimeStamp          Var1
>>
>> 1         2012-06-18 06:00:00    3
>> 2         2012-06-18 06:02:00    3
>> 3         2012-06-18 06:04:00     3
>> 4         2012-06-18 06:06:00     4
>> 5         2012-06-18 06:08:00     4
>> 6         2012-06-18 06:10:00     4
>>
>> So basically the old time interval is 6 min, but the new ones I would like
>> to have is 2 min.
>
> Assuming dat2 is the result of the line of R code above that does the
> replication and that TimeStamp is of POSIXct class try this:
>

That should be:

     dat2$TimeStamp <- dat2$TimeStamp + 60 * seq(0, 4, 2))

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
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