Q. Write a function called col_median() that takes one argument df and returns the vector of column medians.
col_median <- function(df) {
output <- vector("double", ncol(df))
for (i in seq_along(df)) {
output[[i]] <- median(df[[i]])
}
output
}
While working on this problem, I was using the following line of code that doesn’t work. Can someone kindly explain why? output[i] <- median (df[i])