Imagine you need to calculate the median of each column in a data frame in R. How would you do this?

  • Use the apply() function with the appropriate margin argument and the median() function
  • Use the colMedian() function with the data frame as an argument
  • Use the median() function directly on the data frame
  • Use the median() function with the numeric columns specified by name
To calculate the median of each column in a data frame in R, you would use the apply() function with the appropriate margin argument (2 for columns) and the median() function. This allows you to apply the median() function to each column of the data frame.
Add your answer
Loading...

Leave a comment

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