0

I need to use the s or l apply function to calculate the median price for each county in the housing data frame. County and price are both columns, I don't know how to group based on the county name.

This has probably been asked somewhere, but I've been searching for hours and can't find anything. Sorry, TIA

Amanda
  • 1
  • Please add data using `dput` and show the expected output for the same. Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Feb 20 '20 at 00:33
  • 1
    Probably something like `lapply(split(df, df$county), function(x) median(x$price))`. Or `aggregate(df$price, list(df$county), median)`. Or `by(df, df$county, function(x) median(x$price))`. Or `tapply(df$price, df$county, median)`. – Axeman Feb 20 '20 at 00:37

0 Answers0