Question: Using lapply() on more complicated objects and returning results. To do: use lapply() to iterate over the list of dataframes and return the row of
Using lapply() on more complicated objects and returning results. To do: use lapply() to iterate over the list of dataframes and return the row of the data.frame containing the maximum value of x, but only if the maximum value is greater than or equal to 5. If it is less than 5, return NULL.
set.seed(123)
datList <- lapply(1:6, function(t) {
n <- floor(runif(1, 5, 10))
data.frame(ID = 1:n, x = rnorm(n, 0, 5))})
Finally, take the result and bind together the results by row using do.call() with the appropriate function arguments. What happens to the NULL list elements?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
