Skip to content
Prev 276779 / 398506 Next

Sorting Panel Data by Time

Here's another approach using the plyr and data.table packages, where
df is the name I gave to your example data:

# plyr
library('plyr')
ddply(df, .(TIME), mutate, L1 = sort(S1))

# Another way with the data.table package:
library('data.table')
dt <- data.table(df, key = 'TIME')
dt[, list(X1, S1, L1 = sort(S1)), by = 'TIME']

HTH,
Dennis
On Tue, Nov 8, 2011 at 11:58 AM, economicurtis <curtisesjunk at gmail.com> wrote: