how to use apply function with dataframe in r code example Example: how to apply a function to a dataframe in r x = apply(df, MARGIN = 2, FUN = mean)