Applying Functions to Columns
sapply over a data frame runs a function on each column.
Example
df <- data.frame(a = 1:4, b = c(2, 4, 6, 8))
print(sapply(df, mean))
print(colMeans(df))
print(round(sapply(df, sd), 2))
print(Reduce(`+`, df))Exercise
Per column.
(df, mean)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.