[R] By function

Raoni Rodrigues caciquesamurai at gmail.com
Fri Apr 8 00:38:53 CEST 2011

Hello all!

I have a data frame with nine variables and 293 cases. (attached goes
the csv file).

I need to calculate a index using the sum of one variable (N) divided
by the length of other variable (Fisherman), but for each day (Date).

I tried to use that codes:

by (cpue, cpue$Date, function (x) sum (cpue$N)/length(cpue$Fisherman))

tapply (cpue$Data, cpue$Data, function (x) {sum (x)/length(y)})

In both codes, as result, I received the same value for all Date
value. And, oddly, this result is the value of calculation for all
data frame, as I used just:

sum (cpue$N)/length(cpue$Fishermans)

Sorry for the basic question, but I worked on this simple code all day
and can't do it work out! And have no idea why...

I'm using R 2.11 in Windows XP.

Since now, thanks for the attention and all help,



More information about the R-help mailing list