Re: [R] Looking for a sort of tapply() to data frames

2005-12-16 Thread January Weiner
Hi, On 12/15/05, Gabor Grothendieck [EMAIL PROTECTED] wrote: You don't get them as a column but you get them as the component labels. by(df, df$Day, function(x) colMeans(x[,-1])) If you convert it to a data frame you get them as the rownames: do.call(rbind, by(df, df$Day, function(x)

Re: [R] Looking for a sort of tapply() to data frames

2005-12-16 Thread Gabor Grothendieck
On 12/16/05, January Weiner [EMAIL PROTECTED] wrote: Hi, On 12/15/05, Gabor Grothendieck [EMAIL PROTECTED] wrote: You don't get them as a column but you get them as the component labels. by(df, df$Day, function(x) colMeans(x[,-1])) If you convert it to a data frame you get them

Re: [R] Looking for a sort of tapply() to data frames

2005-12-16 Thread Frank E Harrell Jr
Gabor Grothendieck wrote: On 12/16/05, January Weiner [EMAIL PROTECTED] wrote: Hi, On 12/15/05, Gabor Grothendieck [EMAIL PROTECTED] wrote: You don't get them as a column but you get them as the component labels. by(df, df$Day, function(x) colMeans(x[,-1])) If you convert it to a data

Re: [R] Looking for a sort of tapply() to data frames

2005-12-16 Thread Gabor Grothendieck
One other point. The cor example could be done using tapply like this: tapply(rownames(df), df$Day, function(r) cor(df[r,val1], df[r, val2])) On 12/16/05, Gabor Grothendieck [EMAIL PROTECTED] wrote: On 12/16/05, January Weiner [EMAIL PROTECTED] wrote: Hi, On 12/15/05, Gabor Grothendieck

Re: [R] Looking for a sort of tapply() to data frames

2005-12-15 Thread January Weiner
Hello again, On 12/14/05, Thomas Lumley [EMAIL PROTECTED] wrote: You want by(df[,-1], df$Day, function.that.means.each.column) OK, slowly :-) I don't understand it. - why df[,-1] and not df? don't we loose the df$Day entries? (by the way, why does typeof(df) show list? I thought that

Re: [R] Looking for a sort of tapply() to data frames

2005-12-15 Thread Gabor Grothendieck
On 12/15/05, January Weiner [EMAIL PROTECTED] wrote: Hello again, On 12/14/05, Thomas Lumley [EMAIL PROTECTED] wrote: You want by(df[,-1], df$Day, function.that.means.each.column) OK, slowly :-) I don't understand it. - why df[,-1] and not df? don't we loose the df$Day entries? You

[R] Looking for a sort of tapply() to data frames

2005-12-14 Thread January Weiner
Hi, I read about the by() function, but it does not seem to do the job I need. Here is the problem: Say - I have a data frame, with three columns. The first one contains strings that describe the data points, with repeats (for example, days of a week). The other two contain numbers. Something

Re: [R] Looking for a sort of tapply() to data frames

2005-12-14 Thread Thomas Lumley
On Wed, 14 Dec 2005, January Weiner wrote: Hi, I read about the by() function, but it does not seem to do the job I need. Here is the problem: by() will work, you just need to use the right function in it. You want by(df[,-1], df$Day, function.that.means.each.column) so all you need to do