Re: [R] Aggregrate function

2009-02-13 Thread Monica Pisica
help, Monica > Date: Thu, 12 Feb 2009 14:05:44 -0800 > From: spec...@stat.berkeley.edu > To: pisican...@hotmail.com > CC: christos.hat...@nuverabio.com; r-help@r-project.org; markle...@verizon.net > Subject: Re: [R] Aggregrate function > > Monica - > Here's a more c

Re: [R] Aggregrate function

2009-02-12 Thread David Winsemius
Actually what was originally requested is returned by: xveg[xveg$tot %in% with(xveg, tapply(tot, loc, max)), c("loc","sp")] -- David Winsemius On Feb 12, 2009, at 5:59 PM, markle...@verizon.net wrote: it does and you get exactly what monica wanted if you take out the "sp and just return t

Re: [R] Aggregrate function

2009-02-12 Thread David Winsemius
I realized later that the which might not be necessary (and in addition was reminded privately). The %in% function returns a logical vector which works just as well with matrix or dataframe indexing as the numeric vector returned by which. -- David Winsemius On Feb 12, 2009, at 5:52 PM, D

Re: [R] Aggregrate function

2009-02-12 Thread markleeds
it does and you get exactly what monica wanted if you take out the "sp and just return the whole thing. thanks. On Thu, Feb 12, 2009 at 5:52 PM, David Winsemius wrote: aggregate and by are convenience functions of tapply. Consider this alternate solution: xveg[which(xveg$tot %in% with(xv

Re: [R] Aggregrate function

2009-02-12 Thread David Winsemius
aggregate and by are convenience functions of tapply. Consider this alternate solution: xveg[which(xveg$tot %in% with(xveg, tapply(tot, loc, max))),"sp"] It uses tapply to find the maximums by loc(ations) and then to goes back into xveg to find the corresponding sp(ecies). You should do testing

Re: [R] Aggregrate function

2009-02-12 Thread Phil Spector
d,temp) print(result) Thanks so much again, Monica From: christos.hat...@nuverabio.com To: pisican...@hotmail.com; r-help@r-project.org Subject: RE: [R] Aggregrate function Date: Thu, 12 Feb 2009 15:56:38 -0500 I don't have an easy solution with aggregate, because the function in a

Re: [R] Aggregrate function

2009-02-12 Thread Christos Hatzis
-Christos > -Original Message- > From: Monica Pisica [mailto:pisican...@hotmail.com] > Sent: Thursday, February 12, 2009 4:35 PM > To: christos.hat...@nuverabio.com; R help project; > markle...@verizon.net > Subject: RE: [R] Aggregrate function > > > Hi, > &g

Re: [R] Aggregrate function

2009-02-12 Thread Monica Pisica
,sp=paste(.df$sp[maxindices],collapse=","),tot=max(.df$tot)) }) result <- do.call(rbind,temp) print(result) Thanks so much again, Monica > From: christos.hat...@nuverabio.com > To: pisican...@hotmail.com; r-help@r-project.org > Subject: RE: [R] Aggregrate function &g

Re: [R] Aggregrate function

2009-02-12 Thread Christos Hatzis
I don't have an easy solution with aggregate, because the function in aggregate needs to return a scalar. But the following should work: do.call("rbind", lapply(split(xveg, xveg$loc), function(x) x[which.max(x$tot), ])) loc sp tot L1 L1 b 60 L2 L2 e 30 L3 L3 b 68 -Christos > -O

Re: [R] Aggregrate function

2009-02-12 Thread Jorge Ivan Velez
Dear Monica, Try this xveg[with(xveg, tot %in% tapply(tot,loc,max)),] HTH, Jorge On Thu, Feb 12, 2009 at 1:58 PM, Monica Pisica wrote: > > Hi, > > I have to recognize that i don't fully understand the aggregate function, > but i think it should help me with what i want to do. > > xveg is a