I am trying to run this code to find the mean of each column.
df <- data.frame(
a = rnorm(10),
b = rnorm(10),
c = rnorm(10),
d = rnorm(10)
)
output <- vector("double", length = ncol(df))
for(i in seq_along(df)) {
output[i] <- mean(df[i])
}
output
I am getting error for not using df[[i]] though df[1] is slicing the data frame and returning the result.