Error in Function : invalid ‘type’ (list) of argument in R (2 Examples)
In this article you’ll learn how to deal with the “Error in FUN : invalid ‘type’ (list) of argument” in R.
Creation of Exemplifying Data
x <- list(7, 5, 3, 1) # Construct list in R x # Display example list in RStudio console # [[1]] # [1] 7 # # [[2]] # [1] 5 # # [[3]] # [1] 3 # # [[4]] # [1] 1 |
x <- list(7, 5, 3, 1) # Construct list in R x # Display example list in RStudio console # [[1]] # [1] 7 # # [[2]] # [1] 5 # # [[3]] # [1] 3 # # [[4]] # [1] 1
Example 1: Replicating the Error Message in FUN : invalid ‘type’ (list) of argument
sum(x) # Try to apply sum to list # Error in sum(x) : invalid 'type' (list) of argument |
sum(x) # Try to apply sum to list # Error in sum(x) : invalid 'type' (list) of argument
Example 2: Solving the Error Message in FUN : invalid ‘type’ (list) of argument
sum(unlist(x)) # Apply sum function to vector # [1] 16 |
sum(unlist(x)) # Apply sum function to vector # [1] 16