[R] Binding result of a function to a data frame
Gundala Viswanath
gundalav at gmail.com
Tue Jun 24 04:31:56 CEST 2008
Hi,
I have the following function:
> kurtosis <-function(x) (mean((x-mean(x))^4))/(sd(x)^4) #x is a vector
and data
> print(mydata)
V1 V2 V3 V4 V5
1 1007_s_at DDR1 2865.1 2901.3 1978.3
2 1053_at RFC2 103.6 81.6 108.0
3 117_at HSPA6 222.0 222.5 306.2
4 121_at PAX8 2146.3 2457.2 1901.9
5 1255_g_at GUCA1A 226.5 321.2 109.2
6 1294_at UBE1L 296.6 424.6 406.1
7 1316_at THRA 339.9 354.2 178.3
8 1320_at PTPN21 78.4 36.2 185.2
Now, I want to:
1. apply the kurtosis function to every row in the data (starting
from V3 to V5)
2. bind the output of the kurtosis function to mydata.
Why my code below doesn't work? What's the solution for it?
binded_mydata_withkurt <- cbind(mydata,
kurt=apply(mydata,1,kurtosis(mydata[,3:ncol(repo.dat)]),na.rm = TRUE))
- Gundala Viswanath
Jakarta - Indonesia
More information about the R-help
mailing list