Re: [R] efficiently picking one row from a data frame per unique key

2010-04-12 Thread Peter Alspach
ent: Tuesday, 13 April 2010 1:34 p.m. > To: r-help@r-project.org > Subject: [R] efficiently picking one row from a data frame per unique > key > > Hello all, I'm trying to transform data frames by grouping the rows by > the > values in a particular column, ordered by anot

Re: [R] efficiently picking one row from a data frame per unique key

2010-04-12 Thread Phil Spector
James - If I understand you correctly: getone = function(df)df[order(df$x,df$y),][1,] describes what you want from each data frame corresponding to a unique value of x. Then, supposing that your data frame is called df: sdf = split(df,df$x) will create a list of data frames for the uniqu

[R] efficiently picking one row from a data frame per unique key

2010-04-12 Thread James Kebinger
Hello all, I'm trying to transform data frames by grouping the rows by the values in a particular column, ordered by another column, then picking the first row in each group. I'd like to convert a data frame like this: x y z 1 10 20 1 11 19 2 12 18 4 13 17 into one with three rows, like this,