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
nlight    Alewife 0.02816901 #4 230 Sunlight    Alewife 0.05633803 #5 230 Sunlight    Alewife 0.22535211 #6 230 Sunlight    Alewife 0.30985915 A.K. - Original Message - From: Sally_roman To: r-help@r-project.org Cc: Sent: Thursday, October 25, 2012 10:19 AM Subject: [R] tr

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

[R] trying ti use a function in aggregate

2012-10-25 Thread Sally_roman
Hi -I am using R v 2.13.0. I am trying to use the aggregate function to calculate the percent at length for each Trip_id and CommonName. Here is a small subset of the data. Trip_id Vessel CommonName Length Count 1 230SunlightShad,American 19 1 2 2