r - Error (invalid length argument) while calling a function -
i writing function check mean of numeric columns in data frame. below code have written.
means_func <- function(x) { nc <- ncol(sapply(x,is.numeric)) #selecting numeric columns means <- numeric(nc) #assigning result (i in nc) { means[i] <- mean(x[i]) } means } means_func(airquality) #calling function
but when call function, error error in numeric(nc) : invalid 'length' argument
Comments
Post a Comment