I have a list (in R) where the elements are different data types, e.g., the first element is numeric and the second element is character. I would like to apply a different function to each element. For example, in the code below I try to apply the sum function only to the first element and the length function only to the second element. Is there a way to apply a different function to each element of a list (without breaking up the list)?

data <- list( A = rnorm(10), B = letters[1:10] ) lapply(data, list(sum, length)) mapply(function(x) sum, length, data)