I'm trying to calculate the mean and standard deviation of several columns (except the first column) in a data.frame with NA
values.
I've tried colMeans
, sapply
, etc., to create a loop that runs through the data.frame and then stores means and standard deviations in a separate table but keep getting a "FUN" error. any help would be great. Thanks
a
The functions you should be using (e.g.
colMeans
) will almost all have a parameter calledna.rm
which defaults toFALSE
. Just docolMeans(x = your_df, na.rm = TRUE)
and you'll be good to go. Same with using justmean()
if you want to go column by column.The following example code may prove useful.
For the standard deviation, replace
mean()
withsd()
.