Thanks Arun,

this is great. However, it should be just a little bit different:

#  id  event       time time_on_task
#1  1    add 1373502892           80
#2  2    add 1373502972           23
#3  3 delete 1373502995           901
#4  4   view 1373503896          100
#5  5    add 1373503996          NA

When I calculate difference, I need to know how long each activity was. It
is id2-id1 for the first activity...


On Thu, Aug 29, 2013 at 11:03 AM, arun <smartpink...@yahoo.com> wrote:

>
>
> Hi,
> Try:
> dat1<- read.table(text="
> id    event    time
> 1    add      1373502892
> 2    add      1373502972
> 3    delete  1373502995
> 4    view      1373503896
> 5    add      1373503996
> ",sep="",header=TRUE,stringsAsFactors=FALSE)
>  dat1$time_on_task<- c(NA,diff(dat1$time))
>  dat1
> #  id  event       time time_on_task
> #1  1    add 1373502892           NA
> #2  2    add 1373502972           80
> #3  3 delete 1373502995           23
> #4  4   view 1373503896          901
> #5  5    add 1373503996          100
>
> #Not sure whether this depends on the values of "event" or not..
> A.K.
>
>
>
>
>
> ----- Original Message -----
> From: srecko joksimovic <sreckojoksimo...@gmail.com>
> To: R help <R-help@r-project.org>
> Cc:
> Sent: Thursday, August 29, 2013 1:52 PM
> Subject: [R] Add new calculated column to data frame
>
> Hi,
>
> I have a following data set:
> id    event    time (in sec)
> 1     add      1373502892
> 2     add      1373502972
> 3     delete   1373502995
> 4     view      1373503896
> 5     add       1373503996
> ...
>
> I'd like to add new column "time on task" which is time elapsed between two
> events (id2 - id1...). What would be the best approach to do that?
>
> Thanks,
> Srecko
>
>     [[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.
>
>

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

Reply via email to