Re: [R] trying ti use a function in aggregate

2012-10-25 Thread arun
  Alewife 22    16 0.22535211 #6 230 Sunlight    Alewife 23    22 0.30985915 A.K. - Original Message - From: Rui Barradas To: Sally_roman Cc: r-help@r-project.org Sent: Thursday, October 25, 2012 11:59 AM Subject: Re: [R] trying ti use a function in aggregate Hello, Try the

Re: [R] trying ti use a function in aggregate

2012-10-25 Thread arun
o: Sally_roman Cc: r-help@r-project.org Sent: Thursday, October 25, 2012 2:45 PM Subject: Re: [R] trying ti use a function in aggregate Sally, It's great that you provided data and code.  To make it even more user-friendly for R-help readers, supply your data as Rcode, using (for example) t

Re: [R] trying ti use a function in aggregate

2012-10-25 Thread Sally_roman
Hi Jean - Thank you for your help. The code worked great. - Original Message - From: "Jean V Adams [via R]" To: "Sally_roman" Sent: Thursday, October 25, 2012 2:48:45 PM Subject: Re: trying ti use a function in aggregate Sally, It's great that you provided data and code. To make

Re: [R] trying ti use a function in aggregate

2012-10-25 Thread arun
___ From: Sally A Roman To: arun Sent: Thursday, October 25, 2012 12:44 PM Subject: Re: [R] trying ti use a function in aggregate Thank you for your help.  Your code does what I need it to, but the output that I need is Trip_id, Vessel, CommonName, Length, Percent.  When I run your

Re: [R] trying ti use a function in aggregate

2012-10-25 Thread Jean V Adams
Sally, It's great that you provided data and code. To make it even more user-friendly for R-help readers, supply your data as Rcode, using (for example) the dput() function. The reason you were getting all 1s with your code, is that you had told it to aggregate by trip, LENGTH, and species.

Re: [R] trying ti use a function in aggregate

2012-10-25 Thread arun
Hi, May be this helps: dat1<-read.table(text="  Trip_id  Vessel  CommonName Length Count 1  230    Sunlight    ShadAmerican    19    1 2  230    Sunlight    ShadAmerican    20    1 3  230    Sunlight    ShadAmerican    21    1 4  230    Sunlight    ShadAm

Re: [R] trying ti use a function in aggregate

2012-10-25 Thread Rui Barradas
Hello, Try the following. (I've changed your function a bit. And named the data.frame 'dat', not 'data', which is an R function.) myfun <- function (x) ifelse(sum(x) == 0, 0, x/sum(x)) aggregate(Count ~ Trip_id + Length + CommonName, data = dat, myfun) The output shows that each and every gr