I have the following sample dataset (CSV input here:http://goo.gl/YR8LP. CSV output here: http://goo.gl/EFCC8) which I want to transform as follows. For each person in a household I want to create two new variables OrigTAZ and DestTAZ. It should take the value in TripendTAZ and put that in DestTAZ. For OrigTAZ it should put value of TripendTAZ from the previous row. For the first trip of every person in a household (Tripid = 1) the OrigTAZ = hometaz. For each person in a household, from the second trip OrigTAZ = TripendTAZ_(n-1) (the value of TripendTAZ from the previous row) and DestTAZ = TripEndTAZ. The sample input and output data are shown in the links above. I tried the suggestions shown here: Basic lag in R vector/dataframe<http://stackoverflow.com/questions/3558988/basic-lag-in-r-vector-dataframe> but have not had luck.
TIA, Krishnan -- Krishnan Viswanathan 1101 High Meadow Dr Tallahassee FL 32311 [[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.