Re: [R] Mean not working in function

2014-04-16 Thread arun
Hi, Try: set.seed(48) dat1 <- data.frame(matrix(sample(c(NA, 1:20), 4 * 20, replace = TRUE), ncol = 4), fac1 = sample(LETTERS, 20, replace = TRUE)) mysummary <- function(dataf) { indx <- sapply(dataf, is.numeric) for (name in names(dataf)[indx]) { cat("Variable name: ", name, ": Mean=", mean(da

Re: [R] Mean not working in function

2014-04-11 Thread arun
Hi, Try: mysummary <- function(dataf){ for(name in names(dataf)){ cat ("Variable name: ", name, ": Mean=", mean(dataf[,name],na.rm=TRUE),"\n") } }  ##Using some example data: set.seed(48) dat1 <- as.data.frame(matrix(sample(c(NA,1:20),4*20,replace=TRUE),ncol=4)) mysummary(dat1) #Variable name: