Re: [R] Creating two new variables conditional on retaining values from previous rows

2016-04-19 Thread Jim Lemon
Hi pele, There are probably more elegant ways to do this using some function, but this might help: psdat<-read.table(text="ID DATE ITEM 1 1/1/2014P1 1 1/15/2014 P2 1 1/20/2014 P3 1 1/22/2014 P4 1 3/10/2015 P5 2 1/13/2015 P1 2 1/20/2015 P2 2 1/28/2015 P3 2

Re: [R] Creating two new variables conditional on retaining values from previous rows

2016-04-19 Thread Bert Gunter
I do not have the tenacity to decipher your logic, but I would suggest that you go through an R tutorial or two instead of limiting yourself to R-Help (not R forum?) archives. You probably are going about it wrongly in R (I suspect you need indexing). In fact, I would guess that you probably don't

[R] Creating two new variables conditional on retaining values from previous rows

2016-04-19 Thread pele.s--- via R-help
Hello, Iam looking for an R solution that can efficiently produce the output shown below. I can produce this easily in SAS with retain statement and a few lines of if-then-else logic, etc.. but I am not find anything similar on the Rforum archives. Below is the logic I am trying to apply to pro