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

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

Leave a comment

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