[R] aggregate factor

2007-09-07 Thread Bill Szkotnicki
Hi, I am using aggregate to compute means for later plotting. There are two factors involved and the problem is that the values of the second factor ( Age ) in the means are not in the right order because 10 comes inbetween 1 and 2 What I really want is the numeric value of Age but as.numeric

Re: [R] aggregate factor

2007-09-07 Thread ONKELINX, Thierry
: [R] aggregate factor Hi, I am using aggregate to compute means for later plotting. There are two factors involved and the problem is that the values of the second factor ( Age ) in the means are not in the right order because 10 comes inbetween 1 and 2 What I really want is the numeric

[R] Aggregate daily data into weekly sums

2007-07-23 Thread Jacques Wagnor
Dear Lest, I have a two-variable data frame as follows (the time peirod of the actual data set is 10 years): Date Amount 1 6/1/2007 1 2 6/1/2007 1 3 6/4/2007 2 4 6/5/2007 2 5 6/11/2007 3 6 6/12/2007 3 7 6/12/2007 3 8 6/13/2007 3 9

Re: [R] Aggregate daily data into weekly sums

2007-07-23 Thread Henrique Dallazuanna
Hi, Perhaps you can try: df Date Amount 1 2007-06-01 1 2 2007-06-01 1 3 2007-06-04 2 4 2007-06-05 2 5 2007-06-11 3 6 2007-06-12 3 7 2007-06-12 3 8 2007-06-13 3 9 2007-06-13 3 10 2007-06-18 4 11 2007-06-18 4 12 2007-06-25

Re: [R] Aggregate daily data into weekly sums

2007-07-23 Thread antonio rodriguez
Or, z-mydata #zoo object new.time - as.Date(7 * floor(as.numeric(time(z))/7) + 7) z2 - aggregate(z, new.time, mean) Henrique Dallazuanna escribió: Hi, Perhaps you can try: df Date Amount 1 2007-06-01 1 2 2007-06-01 1 3 2007-06-04 2 4 2007-06-05

Re: [R] Aggregate daily data into weekly sums

2007-07-23 Thread Gabor Grothendieck
Try this. I have changed output format to yyy/mm/Weekw so its ordered. Lines - Date Amount 6/1/2007 1 6/1/2007 1 6/4/2007 2 6/5/2007 2 6/11/2007 3 6/12/2007 3 6/12/2007 3 6/13/2007 3 6/13/2007 3 6/18/2007 4 6/18/2007 4 6/25/2007

[R] aggregate by two columns, sum not working while mean is

2007-06-07 Thread Guanrao Chen
Dear Fellow Rers, I have a table looks like this: ca, la, 12 ca, sd, 22 ca, la, 33 nm, al, 9 ma, lx, 18 ma, bs, 90 ma, lx, 22 I want to sum the 3rd column grouped by the first and the second column, so the result look like this table: ca, la, 45 ca, sd, 22 nm, al, 9 ma, lx, 40 ma, bs, 90

Re: [R] aggregate by two columns, sum not working while mean is

2007-06-07 Thread jim holtman
This seems to work fine: x - ca, la, 12 + ca, sd, 22 + ca, la, 33 + nm, al, 9 + ma, lx, 18 + ma, bs, 90 + ma, lx, 22 + table - read.csv(textConnection(x), header=FALSE) aggregate(table$V3,list(table$V1,table$V2),mean) Group.1 Group.2x 1 nm al 9.0 2 ma bs 90.0 3

Re: [R] aggregate in zoo

2007-06-01 Thread Gabor Grothendieck
On 6/1/07, Alfonso Sammassimo [EMAIL PROTECTED] wrote: Hi R-experts, Thanks very much to Jim Holtman and Gabor on my previous question. I am having another problem with data manipulation in zoo. The following is data (Z) for first business day of every month in zoo format. I am trying to

[R] Aggregate to find majority level of a factor

2007-05-31 Thread Thompson, Jonathan
I want to use the aggregate function to summarize data by a factor (my field plots), but I want the summary to be the majority level of another factor. For example, given the dataframe: Plot1 big Plot1 big Plot1 small Plot2 big Plot2 small Plot2 small Plot3

Re: [R] Aggregate to find majority level of a factor

2007-05-31 Thread Martin Henry H. Stevens
How about tapply? plot - gl(2,3); plot type - letters[c(1,2,2,1,1,1)]; type tapply(type, list(plot), function(x) {tabl - table(x) names(tabl[tabl==max (tabl)])}) Hank On May 31, 2007, at 3:25 PM, Thompson, Jonathan wrote: I want to use the

Re: [R] Aggregate to find majority level of a factor

2007-05-31 Thread Marc Schwartz
On Thu, 2007-05-31 at 12:25 -0700, Thompson, Jonathan wrote: I want to use the aggregate function to summarize data by a factor (my field plots), but I want the summary to be the majority level of another factor. For example, given the dataframe: Plot1 big Plot1 big Plot1

Re: [R] Aggregate to find majority level of a factor

2007-05-31 Thread Peter Alspach
PROTECTED] On Behalf Of Thompson, Jonathan Sent: Friday, 1 June 2007 7:26 a.m. To: r-help@stat.math.ethz.ch Subject: [R] Aggregate to find majority level of a factor I want to use the aggregate function to summarize data by a factor (my field plots), but I want the summary to be the majority

Re: [R] Aggregate to find majority level of a factor

2007-05-31 Thread Mike Lawrence
This should do the trick. Also labels ties with NA. a=as.data.frame(cbind(c(1,1,1,2,2,2,3,3,3,4,4),c ('big','big','small','big','small','small','small','small','small','big' ,'small'))) a$V2=factor(a$V2) maj=function(x){ y=table(x) z=which.max(y) if(sum(y==max(y))==1){

[R] aggregate in zoo

2007-05-31 Thread Alfonso Sammassimo
Hi R-experts, Thanks very much to Jim Holtman and Gabor on my previous question. I am having another problem with data manipulation in zoo. The following is data (Z) for first business day of every month in zoo format. I am trying to get mean of open for each year. I subset Z - Z[,2] then

[R] aggregate similar to SPSS

2007-04-25 Thread Natalie O'Toole
Hi, Does anyone know if: with R can you take a set of numbers and aggregate them like you can in SPSS? For example, could you calculate the percentage of people who smoke based on a dataset like the following: smoke = 1 non-smoke = 2 variable 1 1 1 2 2 1 1 1 2 2 2 2 2 2 When aggregated, SPSS

Re: [R] aggregate similar to SPSS

2007-04-25 Thread Dylan Beaudette
?table On Wednesday 25 April 2007 14:32, Natalie O'Toole wrote: Hi, Does anyone know if: with R can you take a set of numbers and aggregate them like you can in SPSS? For example, could you calculate the percentage of people who smoke based on a dataset like the following: smoke = 1

Re: [R] aggregate similar to SPSS

2007-04-25 Thread Andrew Robinson
Hi Nat, can I suggest, without offending, that you purchase and read Peter Dalgaard's Introductory Statistics with R or Michael Crawley's Statistics: An Introduction using R or Venables and Ripley's Modern Applied Statistics with S or Maindonald and Braun's Data Analysis and Graphics Using R: An

Re: [R] aggregate similar to SPSS

2007-04-25 Thread Tim Churches
Andrew Robinson [EMAIL PROTECTED] wrote: can I suggest, without offending, that you purchase and read Peter Dalgaard's Introductory Statistics with R or Michael Crawley's Statistics: An Introduction using R or Venables and Ripley's Modern Applied Statistics with S or Maindonald and Braun's

[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 with numerous factors

2006-12-18 Thread Joachim Claudet
Dear list members, I am facing some problems using the aggregate() function. I want to calculate a sum and a mean of one variable over the combination of 12 factors with the aggregate() function to avoid loops but it doesn't work (or the job is far too long, it exceeds 2 hours). It works with

Re: [R] Aggregate with numerous factors

2006-12-18 Thread Peter Dalgaard
Joachim Claudet wrote: Dear list members, I am facing some problems using the aggregate() function. I want to calculate a sum and a mean of one variable over the combination of 12 factors with the aggregate() function to avoid loops but it doesn't work (or the job is far too long, it

Re: [R] Aggregate with numerous factors

2006-12-18 Thread Peter Dalgaard
Peter Dalgaard wrote: Alternatively, rewrite aggregate() and send us a patch ;-) It is not necessarily all that hard. Here's a rough idea IX - as.data.frame(by) OO - do.call(order,IX) Y - x[OO,] g - cumsum(!duplicated(IX)) FF - unique(IX) cbind(FF, sapply(split(x,g),FUN)) (completely

[R] Aggregate?

2006-12-08 Thread Gustaf Rydevik
Hi All, I think i'm failing to undersatnd how aggregate() is supposed to work. example: test1-sample(c(0,1),100,replace=T) test2-sample(letters,100,replace=T) aggregate(test1,list(test2),sum) Error in data.frame(w, lapply(y, unlist, use.names = FALSE)) : arguments imply differing

Re: [R] Aggregate?

2006-12-08 Thread Ingmar Visser
It does that for me without errors ... (R 2.3.1 on Mac OSX 10.4.8) Best, Ingmar From: Gustaf Rydevik [EMAIL PROTECTED] Date: Fri, 8 Dec 2006 12:58:01 +0300 To: r-help@stat.math.ethz.ch Subject: [R] Aggregate? Hi All, I think i'm failing to undersatnd how aggregate() is supposed to work

Re: [R] Aggregate?

2006-12-08 Thread Petr Pikal
: Gustaf Rydevik [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Subject:[R] Aggregate? Hi All, I think i'm failing to undersatnd how aggregate() is supposed to work. example: test1-sample(c(0,1),100,replace=T) test2-sample(letters,100,replace=T) aggregate

Re: [R] Aggregate with multiple statistics?

2006-10-24 Thread Alex Brown
Try the summary function, which pretty much does exactly that. -Alex On 20 Oct 2006, at 23:44, Jonathan Greenberg wrote: Is there a way to calculate, say, the mean, min and max using aggregate using one line of code? Or do I need to call them separately (e.g. aggregate(...,mean);

[R] Aggregate with multiple statistics?

2006-10-20 Thread Jonathan Greenberg
Is there a way to calculate, say, the mean, min and max using aggregate using one line of code? Or do I need to call them separately (e.g. aggregate(...,mean); aggregate(...,min)) and then merge the data back together? --j -- Jonathan A. Greenberg, PhD NRC Research Associate NASA Ames Research

Re: [R] Aggregate with multiple statistics?

2006-10-20 Thread Gabor Grothendieck
Try summaryBy in package doBy. e.g. using the built in dataset CO2: summaryBy(uptake ~ Plant, CO2, FUN = c(mean, min, max)) On 10/20/06, Jonathan Greenberg [EMAIL PROTECTED] wrote: Is there a way to calculate, say, the mean, min and max using aggregate using one line of code? Or do I need to

Re: [R] Aggregate with multiple statistics?

2006-10-20 Thread hadley wickham
Try summaryBy in package doBy. e.g. using the built in dataset CO2: summaryBy(uptake ~ Plant, CO2, FUN = c(mean, min, max)) Or with reshape with a little more work: cm - melt(CO2, id=1:4) cast(cm, Type ~ Treatment, c(min,mean,max)) but you get some extra flexibility: cast(cm,

[R] Aggregate Values for All Levels of a Factor

2006-10-05 Thread Kaom Te
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello, I'm a novice user trying to figure out how to retain NA aggregate values. For example, given a data frame with data for 3 of the 4 possible factor colors(orange is omitted from the data frame), I want to calculate the average height by color,

Re: [R] Aggregate Values for All Levels of a Factor

2006-10-05 Thread Marc Schwartz
On Thu, 2006-10-05 at 15:44 -0700, Kaom Te wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello, I'm a novice user trying to figure out how to retain NA aggregate values. For example, given a data frame with data for 3 of the 4 possible factor colors(orange is omitted from the data

[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 example : where is the state.region variable?

2006-08-22 Thread John Kane
? - Original Message - From: John Kane [EMAIL PROTECTED] To: Gabor Grothendieck [EMAIL PROTECTED] Cc: R R-help r-help@stat.math.ethz.ch Sent: Monday, August 21, 2006 6:59 PM Subject: Re: [R] aggregate example : where is the state.region variable? --- Gabor Grothendieck [EMAIL PROTECTED

Re: [R] aggregate example : where is the state.region variable?

2006-08-22 Thread Martin Maechler
Gabor == Gabor Grothendieck [EMAIL PROTECTED] on Mon, 21 Aug 2006 21:03:49 -0400 writes: Gabor It is worthwhile to note that what is being Gabor illustrated here is aggregating a numeric matrix by a Gabor factor using the aggregate.default method and, of Gabor course, a

Re: [R] aggregate example : where is the state.region variable?

2006-08-22 Thread Richard M. Heiberger
there is no factor in the dataset but why there is not one and why a call to another dataset is totally opaque. The reason is purely historical. The state dataset is about 10 years older than the data.frame concept. At the time the state.* variables were constructed it was not possible to

Re: [R] aggregate example : where is the state.region variable?

2006-08-22 Thread John Kane
--- Richard M. Heiberger [EMAIL PROTECTED] wrote: there is no factor in the dataset but why there is not one and why a call to another dataset is totally opaque. The reason is purely historical. The state dataset is about 10 years older than the data.frame concept. At the time

[R] aggregate example : where is the state.region variable?

2006-08-21 Thread John Kane
I was looking ?aggregate and ran the first example aggregate(state.x77, list(Region = state.region), mean) The variables in state.x77 appear to be : state.x77 Population Income Illiteracy Life Exp Murder HS Grad Frost Area Where is the state.region variable coming from?

Re: [R] aggregate example : where is the state.region variable?

2006-08-21 Thread Gabor Grothendieck
Its not part of state.x77. Its a completely separate variable. Try ls(package:datasets) and notice its in the list or try ?state.region and note that its a variable in datasets. On 8/21/06, John Kane [EMAIL PROTECTED] wrote: I was looking ?aggregate and ran the first example

Re: [R] aggregate example : where is the state.region variable?

2006-08-21 Thread Prof Brian Ripley
On Mon, 21 Aug 2006, John Kane wrote: I was looking ?aggregate and ran the first example aggregate(state.x77, list(Region = state.region), mean) The variables in state.x77 appear to be : state.x77 Population Income Illiteracy Life Exp Murder HS Grad Frost Area Where is the

Re: [R] aggregate example : where is the state.region variable?

2006-08-21 Thread John Kane
--- Gabor Grothendieck [EMAIL PROTECTED] wrote: Its not part of state.x77. Its a completely separate variable. Try ls(package:datasets) and notice its in the list or try ?state.region and note that its a variable in datasets. Thanks. I was wondering if it was going something like that.

Re: [R] aggregate example : where is the state.region variable?

2006-08-21 Thread MARK LEEDS
, August 21, 2006 6:59 PM Subject: Re: [R] aggregate example : where is the state.region variable? --- Gabor Grothendieck [EMAIL PROTECTED] wrote: Its not part of state.x77. Its a completely separate variable. Try ls(package:datasets) and notice its in the list or try ?state.region

Re: [R] aggregate example : where is the state.region variable?

2006-08-21 Thread Gabor Grothendieck
It is worthwhile to note that what is being illustrated here is aggregating a numeric matrix by a factor using the aggregate.default method and, of course, a factor can't be part of a numeric matrix. Of course, that is not say that the examples could not be improved in terms of clarity,

[R] aggregate data.frame by one column

2006-06-29 Thread Guo Wei-Wei
Hi, everyone, I have a data.frame named eva like this: IND PARTNO VC1 EO1 EO2 EO3 EO4 EO5 114 114001 2 5 4 4 5 4 114 114001 2 4 4 4 4 4 114 114001 2 4 NA NA NA NA 112 112002 2 3 3 6 2 6 112 112002 2 1 1 3 4 4 112 112003 2 6 6 6 5

Re: [R] aggregate data.frame by one column

2006-06-29 Thread Andrew Robinson
Hi Wei-Wei, try this: eva.agg - aggregate(x = list( VC1=eva$VC1, EO1=eva$EO1, EO2=eva$EO2, EO3=eva$EO3, EO4=eva$EO4, EO5=eva$EO5 ),

Re: [R] aggregate data.frame by one column

2006-06-29 Thread Guo Wei-Wei
Hi Andrew, Thank you very much! It works so well than I can expect. All the best, Wei-Wei 2006/6/30, Andrew Robinson [EMAIL PROTECTED]: Hi Wei-Wei, try this: eva.agg - aggregate(x = list( VC1=eva$VC1, EO1=eva$EO1,

[R] Aggregate?

2006-05-03 Thread Guenther, Cameron
Hello, I have a data set with a grouping variable (TRIPID) and several other variables. TRIPID is repeated in some areas and I would like to use a function like aggregate to sum the variable UNITS according to TRIPID. However I would also like to retain the other variables as they are in the

Re: [R] Aggregate?

2006-05-03 Thread Gabor Grothendieck
Suppose we want to sum C over levels of A and that B is constant within levels of A. Then: DF - data.frame(A = gl(2,2), B = gl(2,2), C = 1:4) # test data do.call(rbind, by(DF, DF$A, function(x) replace(x[1,], C, sum(x$C On 5/3/06, Guenther, Cameron [EMAIL PROTECTED] wrote: Hello, I

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 data.frame using column-specific functions

2006-02-15 Thread Markus Preisetanz
Dear Colleagues, does anybody know how to aggregate a data.frame using different functions for different columns? Sincerely ___ Markus Preisetanz Consultant Client Vela GmbH Albert-Roßhaupter-Str. 32 81369 München fon: +49 (0) 89 742 17-113 fax:

Re: [R] aggregate data.frame using column-specific functions

2006-02-15 Thread Jacques VESLOT
you can use mapply()... z - as.data.frame(matrix(1:3,3,3,T)) mapply(function(x,y) x(y), c(sum,prod,sum), z) Markus Preisetanz a écrit : Dear Colleagues, does anybody know how to aggregate a data.frame using different functions for different columns? Sincerely ___

Re: [R] aggregate data.frame using column-specific functions

2006-02-15 Thread justin bem
Hi have you tried ?aggregate eg df1-aggregate(mydata, list(mean1=x1,mean2=x2),mean) - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list

Re: [R] aggregate vs tapply; is there a middle ground?

2006-02-12 Thread Hans Gardfjell
Thanks Peter! I had a feeling that there must be a simpler, better, more elegant solution. /Hans Peter Dalgaard wrote: hadley wickham [EMAIL PROTECTED] writes: I faced a similar problem. Here's what I did tmp -

[R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread Joseph LeBouton
Dear all, I'm wanting to do a series of comparisons among 4 categorical variables: a - aggregate(y, list(var1, var2, var3, var4), sum) This gets me a very nice 2-dimensional data frame with one column per variable, BUT, as help for aggregate says, empty subsets are removed. I don't see in

[R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread Hans Gardfjell
I faced a similar problem. Here's what I did tmp - data.frame(A=sample(LETTERS[1:5],10,replace=T),B=sample(letters[1:5],10,replace=T),C=rnorm(10)) tmp1 - with(tmp,aggregate(C,list(A=A,B=B),sum)) tmp2 - expand.grid(A=sort(unique(tmp$A)),B=sort(unique(tmp$B))) merge(tmp2,tmp1,all.x=T) At least

Re: [R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread hadley wickham
I faced a similar problem. Here's what I did tmp - data.frame(A=sample(LETTERS[1:5],10,replace=T),B=sample(letters[1:5],10,replace=T),C=rnorm(10)) tmp1 - with(tmp,aggregate(C,list(A=A,B=B),sum)) tmp2 - expand.grid(A=sort(unique(tmp$A)),B=sort(unique(tmp$B))) merge(tmp2,tmp1,all.x=T) At

Re: [R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread Joseph LeBouton
Thanks, Phil! I've literally spent two hours on my own trying to find something that does exactly that. Thanks for another pair of functions added to my (slowly!) growing R vocabulary. -jlb Phil Spector wrote: Joseph - I'm sure there are clearer and more efficient ways to do it, but

Re: [R] aggregate vs tapply; is there a middle ground?

2006-02-11 Thread Peter Dalgaard
hadley wickham [EMAIL PROTECTED] writes: I faced a similar problem. Here's what I did tmp - data.frame(A=sample(LETTERS[1:5],10,replace=T),B=sample(letters[1:5],10,replace=T),C=rnorm(10)) tmp1 - with(tmp,aggregate(C,list(A=A,B=B),sum)) tmp2 -

[R] aggregate and ordered factors, feature?

2005-12-19 Thread David James
Hi, aggregate() does not preserve the order of levels for ordered factors, e.g., levs - c(Low, Med, Hi) d - data.frame(x = 1:30, fac = ordered(rep(levs, 10), levels = levs)) out - aggregate(d[,x], by = list(fac=d$f), FUN = mean) cat(Original ordered levels:, levels(d$fac), \n)

Re: [R] aggregate slow with many rows - alternative?

2005-10-14 Thread TEMPL Matthias
Hi, Yesterday, I have analysed data with 16 rows and 10 columns. Aggregation would be impossible with a data frame format, but when converting it to a matrix with *numeric* entries (check, if the variables are of class numeric!) the computation needs only 7 seconds on a Pentium III. I´m

Re: [R] aggregate slow with many rows - alternative?

2005-10-14 Thread jim holtman
Here is the way that I would do it. Using 'lapply' to process the list and create a matrix; take less than 1 second: dat - data.frame(D=sample(32000:33000, 33000, T), + Fid=sample(1:10,33000,T), A=sample(1:5,33000,T)) system.time({ + result - lapply(split(seq(nrow(dat)), dat$D), function(.d){ #

Re: [R] aggregate slow with many rows - alternative?

2005-10-14 Thread Hans-Peter
Many thanks for all your answers. Converting to a matrix didn't help, I tried with Hmisc but didn't get anywhere (different summary functions, multiple levels). 2005/10/14, jim holtman [EMAIL PROTECTED]: Here is the way that I would do it. Using 'lapply' to process the list and create a

[R] aggregate slow with many rows - alternative?

2005-10-13 Thread Hans-Peter
Hi, I use the code below to aggregate / cnt my test data. It works fine, but the problem is with my real data (33'000 rows) where the function is really slow (nothing happened in half an hour). Does anybody know of other functions that I could use? Thanks, Hans-Peter -- dat -

Re: [R] aggregate slow with many rows - alternative?

2005-10-13 Thread Gabor Grothendieck
Convert dat to a matrix and see if working with the matrix instead of a data frame speeds things up enough. On 10/13/05, Hans-Peter [EMAIL PROTECTED] wrote: Hi, I use the code below to aggregate / cnt my test data. It works fine, but the problem is with my real data (33'000 rows) where the

Re: [R] aggregate slow with many rows - alternative?

2005-10-13 Thread Frank E Harrell Jr
Gabor Grothendieck wrote: Convert dat to a matrix and see if working with the matrix instead of a data frame speeds things up enough. In the Hmisc package the asNumericMatrix and matrix2dataFrame functions facilite this. Also look at the summarize and mApply functions in Hmisc, which can be

[R] aggregate

2005-08-30 Thread Omar Lakkis
How can I aggregate this data.frame to list the min and max date for each unique id? From this : r = data.frame(id=rep(seq(1:3), 3), date= as.Date(c(rep(2005-08-25,3), rep(2005-08-26,3), rep(2005-08-29, 3)), %Y-%m-%d)) r id date 1 2005-08-25 2 2005-08-25 3 2005-08-25 1

Re: [R] aggregate

2005-08-30 Thread Dimitris Rizopoulos
://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Omar Lakkis [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Tuesday, August 30, 2005 4:36 PM Subject: [R] aggregate How can I aggregate this data.frame to list the min and max date for each unique id? From this : r

[R] aggregate?

2005-06-17 Thread alex diaz
Dear all: Here is my problem: Example data: dat-data.frame(x=rep(c(a,b,c,d),2),y=c(10:17)) If I wanted to aggregate each level of column dat$x I could use: aggregate(dat$y,list(x=dat$x),sum) But I just want to aggregate two levels (?c? and ?d?) to obtain a new level ?e? I am expecting

Re: [R] aggregate?

2005-06-17 Thread Gabor Grothendieck
On 6/17/05, alex diaz [EMAIL PROTECTED] wrote: Dear all: Here is my problem: Example data: dat-data.frame(x=rep(c(a,b,c,d),2),y=c(10:17)) If I wanted to aggregate each level of column dat$x I could use: aggregate(dat$y,list(x=dat$x),sum) But I just want to aggregate two levels (c

[R] aggregate and stack

2005-05-25 Thread Paulo Brando
Dear All, I have tried to calculate tree mean growth but I think the structure I used below (growthresumo) is not the most elegant, even though it worked. The only problem I had in this first part was that I cannot use 'summary', just 'mean' (sorry but 'R' is pretty new for me). growthresumo

Re: [R] aggregate and stack

2005-05-25 Thread Stephen D. Weigand
Dear Paulo, On May 25, 2005, at 8:01 PM, Paulo Brando wrote: Dear All, I have tried to calculate tree mean growth but I think the structure I used below (growthresumo) is not the most elegant, even though it worked. The only problem I had in this first part was that I cannot use

[R] aggregate

2005-05-11 Thread Omar Lakkis
I have a data frame of daily open, high, low and settle prices. How can I aggregate this data weekly? The data frame has five columns, the first is the date column and the rest are the prices. __ R-help@stat.math.ethz.ch mailing list

RE: [R] aggregate

2005-05-11 Thread bogdan romocea
: Wednesday, May 11, 2005 3:45 PM To: r-help@stat.math.ethz.ch Subject: [R] aggregate I have a data frame of daily open, high, low and settle prices. How can I aggregate this data weekly? The data frame has five columns, the first is the date column and the rest are the prices

Re: [R] aggregate

2005-05-11 Thread bogdan romocea
$c),list(wk),mean) colnames(aggr) - etc -Original Message- From: Omar Lakkis [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 11, 2005 3:45 PM To: r-help@stat.math.ethz.ch Subject: [R] aggregate I have a data frame of daily open, high, low and settle prices. How can I aggregate

[R] Aggregate lag

2005-05-10 Thread Matthieu Cornec
hello, Does anybody know how to aggregate a lag series ? when I try to use aggregate I get the following message try-ts(1:100,start=c(1985,1),freq=12) aggregate(try,4,mean,na.rm=T) Qtr1 Qtr2 Qtr3 Qtr4 1985258 11 1986 14 17 20 23 1987 26 29 32 35 1988 38 41

Re: [R] Aggregate lag

2005-05-10 Thread Achim Zeileis
. Example: R x - ts(1:20,start=c(1990,1),freq=12) R aggregate(window(x, start = c(1990, 1), end = c(1991, 9), extend = TRUE), 4, mean, na.rm = TRUE) Qtr1 Qtr2 Qtr3 Qtr4 1990 2.0 5.0 8.0 11.0 1991 14.0 17.0 19.5 R aggregate(window(lag(x, k = -1), start = c(1990, 1), end = c(1991

[R] aggregate slow with variables of type 'dates' - how to solve

2005-04-15 Thread Christoph Lehmann
Dear all I use aggregate with variables of type numeric and dates. For type numeric functions, such as sum() are very fast, but similar simple functions, such as min() are much slower for the variables of type 'dates'. The difference gets bigger the larger the 'id' var is - but see this sample

Re: [R] aggregate slow with variables of type 'dates' - how to solve

2005-04-15 Thread Gabor Grothendieck
On 4/15/05, Christoph Lehmann [EMAIL PROTECTED] wrote: Dear all I use aggregate with variables of type numeric and dates. For type numeric functions, such as sum() are very fast, but similar simple functions, such as min() are much slower for the variables of type 'dates'. The difference gets

Re: [R] aggregate slow with variables of type 'dates' - how to solve

2005-04-15 Thread Gabor Grothendieck
On 4/15/05, Christoph Lehmann [EMAIL PROTECTED] wrote: Dear all I use aggregate with variables of type numeric and dates. For type numeric functions, such as sum() are very fast, but similar simple functions, such as min() are much slower for the variables of type 'dates'. The difference gets

[R] aggregate question...

2005-03-31 Thread Jeff D. Hamann
R-folks, Is there a function, like aggregate, that allows users to bin values? I've got to break down a data frame into classes of 5cm (or something like it), and I only know how to do it using code like, signif - symnum( stems$dbh, corr = FALSE, na = FALSE,

Re: [R] aggregate question...

2005-03-31 Thread Marc Schwartz
On Thu, 2005-03-31 at 09:17 -0800, Jeff D. Hamann wrote: R-folks, Is there a function, like aggregate, that allows users to bin values? I've got to break down a data frame into classes of 5cm (or something like it), and I only know how to do it using code like, signif - symnum(

Re: [R] aggregate()

2005-01-06 Thread Petr Pikal
On 6 Jan 2005 at 16:55, Karla Meurk wrote: Hi, some time ago I asked R-help about aggregating data as a result I was able to put together some code which includes the line rain.ag - aggregate(newdata, list(hod6=cut(mindata,6 hours)), mean, na.rm=T) I also want to aggregate daily, and

[R] aggregate()

2005-01-05 Thread Karla Meurk
Hi, some time ago I asked R-help about aggregating data as a result I was able to put together some code which includes the line rain.ag - aggregate(newdata, list(hod6=cut(mindata,6 hours)), mean, na.rm=T) I also want to aggregate daily, and 30 minutely etc. My question is why is it that I get

Re: [R] aggregate()

2005-01-05 Thread Gabor Grothendieck
Karla Meurk ksm32 at student.canterbury.ac.nz writes: : : Hi, some time ago I asked R-help about aggregating data as a result I : was able to put together some code which includes the line : : rain.ag - aggregate(newdata, list(hod6=cut(mindata,6 hours)), mean, : na.rm=T) : : I also want to

[R] aggregate and median

2004-12-21 Thread Philippe Hupé
I am trying to use the function aggregate with the median function but I get the following error: Error in FUN(X[[1]], ...) : Argument INDEX When I replace median by mean, it works perfectly Can someone tell me where the problem comes from? Thx I am running R 2.0.0 on SunOS 5.9 -- Philippe Hupé

Re: [R] aggregate and median

2004-12-21 Thread Petr Pikal
On 21 Dec 2004 at 12:46, Philippe Hup wrote: I am trying to use the function aggregate with the median function but I get the following error: Error in FUN(X[[1]], ...) : Argument INDEX When I replace median by mean, it works perfectly Hi Philippe I suppose that you have some typo in

[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

[R] Aggregate rows to see the number of occurences

2004-06-07 Thread Nicolas STRANSKY
Hi, I have a set of data like the following: [,1] [,2] [1,] 102 [2,]70 [3,]10 [4,]10 [5,] 150 [6,] 174 [7,]40 [8,] 198 [9,] 102 [10,] 195 I'd like to aggregate it in order to obtain the frequency (the number of occurences)

  1   2   >