[R] getting sapply to skip columns with non-numeric data?

r user ruser2006 at yahoo.com
Fri Aug 18 00:04:06 CEST 2006


getting s-apply to skip columns with non-numeric data?
I have a dataframe “x” of w columns.

Some columns are numeric, some are not.

I wish to create a function to calculate the mean and
standard deviation of each numeric column, and then
“bind” the column mean and standard deviation to the
bottom of the dataframe.

e.g. 

tempmean <- apply(data.frame(x), 2, mean, na.rm = T)
xnew <- rbind(x,tempmean)

I am running into one small problem
what is the best
way to have sapply “skip” the non-numeric data and
return NA’s?



More information about the R-help mailing list