Most analysis workflows involve multiple steps, e.g.:
“Take this dataframe, create a new column by combining information from two columns, then take the log of the new column, and then tell me the mean value”
We’ll work on this with the penguins dataframe on the following slide
Approach 1
One approach looks something like this:
library(palmerpenguins)penguins$bill_ratio <- penguins$bill_length_mm/penguins$bill_depth_mmlog_bill_ratio <-log(penguins$bill_ratio)mean_log_bill_ratio <-mean(log_bill_ratio, na.rm =TRUE) # we need na.rm = TRUE to remove some of the NA values# Finally this gets us the answer:mean_log_bill_ratio
[1] 0.9393296
Approach 2
The second approach is to nest all the steps within one another: