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
Use the first few rows of iris as test data and try this
where isnum is 1 for each numeric column and NA for
others.
irish - head(iris)
isnum - ifelse(sapply(iris, class) == numeric, 1, NA)
iris.data - data.matrix(iris)
rbind(iris, colMeans(iris.data) * isnum, sd(iris.data) * isnum)
On 8/17/06,
There's something that either you have not thought of or neglected to tell
us: If you have k variables in the data frame, you will need a data frame
of k variables and one row to be able to rbind() to the bottom of the
original one. What are you going to put in place for non-numeric variables?