[R] aggregate function

2007-04-23 Thread Michel Schnitz
Hello, is there a way to use the aggregate function to calculate monthly mean in case i have one row in data frame that holds the date like -mm-dd? i know that it works for daily means. i also like to do it for monthly and yearly means. maybe there is something like aggregate(x,

Re: [R] aggregate function

2007-04-23 Thread Gabor Grothendieck
try this. The first group of lines recreates your data frame, DF, and the last line is the aggregate: Input - DateTimez 2006-01-01 21:00 6,2 2006-01-01 22:00 5,7 2006-01-01 23:00 3,2 2006-01-02 00:00 7,8 2006-01-02 01:00 6,8 2006-01-02

Re: [R] aggregate function

2007-04-23 Thread Michel Schnitz
it works. thanks a lot. Gabor Grothendieck wrote: try this. The first group of lines recreates your data frame, DF, and the last line is the aggregate: Input - DateTimez 2006-01-01 21:00 6,2 2006-01-01 22:00 5,7 2006-01-01 23:00 3,2 2006-01-02

Re: [R] aggregate function

2007-04-23 Thread Martin Becker
If monthly should aggregate per -mm combination, you could try something like aggregate(x$z,list(cut(as.Date(x$Date),m)),mean) for monthly aggregation and aggregate(x$z,list(cut(as.Date(x$Date),y)),mean) for yearly means. If monthly aggregation should aggregate over different years

[R] aggregate function with 'NA'

2006-10-01 Thread Frank
Dear r-help reader, I have some problems with the aggregate function. My datframe looks like frame Day Time V1 V2 1 M0 3 NA 2 M0 4 NA 3 M0 5 2 4 M1 NA 4 5 M1 10 6 6 T0 4 45 7 T1 4 3 8 T1 3 2 9 T1 6 1 I used the aggegate

Re: [R] aggregate function with 'NA'

2006-10-01 Thread Peter Dalgaard
Frank [EMAIL PROTECTED] writes: aggregate(frame[,c(-1)],list(frame$Day,frame$Time),mean) My problem is now that I do not obtain a 'mean' for Day=M/Time=0 and Day=M/Time=1, because aggregate ignores all values for a grouping variable if NA occurs. No. But mean() will give an NA

Re: [R] aggregate function with 'NA'

2006-10-01 Thread Johan Sandblom
aggregate(frame[,c(-1)],list(frame$Day,frame$Time),mean, na.rm=T) 2006/10/1, Frank [EMAIL PROTECTED]: Dear r-help reader, I have some problems with the aggregate function. My datframe looks like frame Day Time V1 V2 1 M0 3 NA 2 M0 4 NA 3 M0 5 2 4 M1 NA

Re: [R] aggregate function with 'NA'

2006-10-01 Thread Gabor Grothendieck
See ?mean and note the na.rm= argument: aggregate(frame[-1], frame[1:2], mean, na.rm = TRUE) On 10/1/06, Frank [EMAIL PROTECTED] wrote: Dear r-help reader, I have some problems with the aggregate function. My datframe looks like frame Day Time V1 V2 1 M0 3 NA 2 M0 4

Re: [R] aggregate function....

2006-03-31 Thread Stephane CRUVEILLER
Nice trick, thx... Stéphane. On Wed, 2006-03-29 at 11:17 -0500, jim holtman wrote: try 'by': x S_id AF_Class count... R_gc_percent S_length 5 82644971 30 0.4835678 6 826449737 0.4835678 8 82645541 31

[R] aggregate function....

2006-03-29 Thread Stephane CRUVEILLER
Dear R users, I have some trouble with the aggregate function. Here are my data daf S_id AF_Class count... R_gc_percent S_length 5 82644971 30 0.4835678 6 826449737 0.4835678 8 82645541 31 0.5138894 9

Re: [R] aggregate function....

2006-03-29 Thread jim holtman
try 'by': x S_id AF_Class count... R_gc_percent S_length 5 82644971 30 0.4835678 6 826449737 0.4835678 8 82645541 31 0.5138894 9 82645542 11 0.5138894 10 826455431

[R] aggregate function

2004-07-26 Thread Luis Rideau Cruz
Hi all, I have the folowing frame(there are more columns than shown), 1 2 34 5 Year Total TusWhi Norw 1994 1.00 1830 0 355 1995 1.00 0 00 1995 1.00 0

Re: [R] aggregate function

2004-07-26 Thread TEMPL Matthias
Hi, # x ... your frame attach(x) sum(Total[Year==1997 Tus 0]) I hope this helps Best, Matthias -Ursprüngliche Nachricht- Von: Luis Rideau Cruz [mailto:[EMAIL PROTECTED] Gesendet: Montag, 26. Juli 2004 14:52 An: [EMAIL PROTECTED] Betreff: [R] aggregate function Hi all, I

Re: [R] aggregate function

2004-07-26 Thread TEMPL Matthias
Hi, # x ... your frame attach(x) sum(Total[Year==1997 Tus 0]) I hope this helps Best, Matthias Templ -Ursprüngliche Nachricht- Von: Luis Rideau Cruz [mailto:[EMAIL PROTECTED] Gesendet: Montag, 26. Juli 2004 14:52 An: [EMAIL PROTECTED] Betreff: [R] aggregate function

RE: [R] aggregate function

2004-07-26 Thread Liaw, Andy
I would try something like: lapply(frame[3:5], function(i) tapply(frame$Total[i0], frame$Year[i0], sum)) $Tus 1994 1995 1997 1999 1121 $Whi 1995 1997 1999 1.00 4.00 2.04 $Norw 1994 1995 1997 1998 1999 11512 HTH, Andy From: Luis Rideau Cruz Hi

RE: [R] aggregate function

2004-07-26 Thread Gabor Grothendieck
[Sorry if this gets posted twice. I have been having some problems with gmane posting.] We can use rowsum like this: rowsum(frame$Total * (frame[,3:5]0), frame$Year) Tus Whi Norw 1994 1 0.00 1 1995 1 1.00 1 1997 2 4.00 5 1998 0 0.00 1