[R] Binding result of a function to a data frame

From: Gundala Viswanath <gundalav_at_gmail.com>
Date: Tue, 24 Jun 2008 11:31:56 +0900


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))


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 24 Jun 2008 - 02:35:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 24 Jun 2008 - 04:31:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive