Suppose you're given a data frame with both numeric and character variables in R and asked to calculate the mean of each numeric variable. How would you do this?

  • Use the sapply() or lapply() function with the subset of numeric variables and the mean() function
  • Use the apply() function with the appropriate margin argument and the mean() function
  • Use the mean() function directly on the data frame
  • Use the mean() function with the numeric variables specified by name
To calculate the mean of each numeric variable in a data frame in R, you can use the sapply() or lapply() function to apply the mean() function to the subset of numeric variables. This approach allows you to calculate the mean for each numeric variable individually.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *