[R] Applying a function to a subset

2011-05-29 Thread gaiarrido
Here´s my problem, i have developed the function kurtosis (using R-book as a guide) with this commands: kurtosis-function(x) { m4-sum((x-mean(x))^4)/length(x) s4-var(x)^2 m4/s4 - 3 } Then create the object fem, which is the difference between the count of a trait in the left side of the body

Re: [R] Applying a function to a subset

2011-05-29 Thread Jim Holtman
kurtosis(fem[!is.na(fem)]) Sent from my iPad On May 29, 2011, at 4:54, gaiarrido gaiarr...@usal.es wrote: Here´s my problem, i have developed the function kurtosis (using R-book as a guide) with this commands: kurtosis-function(x) { m4-sum((x-mean(x))^4)/length(x) s4-var(x)^2 m4/s4 - 3 }

Re: [R] Applying a function to a subset

2011-05-29 Thread Stephan Kolassa
Or just include is.na=TRUE in the definition of kurtosis(): kurtosis-function(x) { m4-sum((x-mean(x,na.rm=TRUE))^4,na.rm=TRUE)/length(x) s4-var(x,na.rm=TRUE)^2 m4/s4 - 3 } HTH Stephan Am 29.05.2011 11:34, schrieb Jim Holtman: kurtosis(fem[!is.na(fem)]) Sent from my iPad On May 29,

Re: [R] Applying a function to a subset

2011-05-29 Thread gaiarrido
That's it. thanks very much, I save hours if work qith your reply - Mario Garrido Escudero PhD student Dpto. de Biología Animal, Ecología, Parasitología, Edafología y Qca. Agrícola Universidad de Salamanca -- View this message in context: