Complete the code to calculate the mean of each column using apply.
result <- apply(data, [1], mean)The second argument in apply specifies the margin: 2 means apply the function to columns.
Complete the code to calculate the sum of each element in the list using lapply.
result <- lapply(numbers, [1])In lapply, you pass the function name without parentheses to apply it to each element.
Fix the error in the for loop to correctly calculate the squares of numbers.
squares <- numeric(length(numbers)) for (i in [1](numbers)) { squares[i] <- numbers[i]^2 }
seq_along(numbers) generates a sequence from 1 to the length of numbers, which is safe for indexing.
Fill both blanks to create a named vector with the mean of each column using sapply.
result <- sapply(data, [1]) names(result) <- [2](data)
sum instead of mean changes the calculation.rownames assigns wrong names.sapply applies mean to each column, and colnames gets the column names for naming the result.
Fill all three blanks to create a list of logical vectors indicating which elements are greater than 5 using lapply.
result <- lapply(numbers, function(x) x [1] [2]) names(result) <- [3](numbers)
length instead of names assigns wrong names.The anonymous function checks if each element is greater than 5 using > and 5. The names function assigns the original names to the result list.