![](/img/trans.png)
[英]Is there a way to find the median using beta distribution parameters in R?
[英]using count to find top 5 median r
structure(list(price = c(80, 115, 46, 32, 100, 71, 175, 150,
139, 190, 85, 64, 79, 60, 55, 70, 120, 50, 280, 75), neighbourhood = c("New Town",
"Southside", NA, "Leith", "Southside", "Old Town", "New Town",
"West End", "Leith", "West End", "New Town", "Leith", "Leith",
NA, "Haymarket", "Morningside", "New Town", "Leith", "Newington",
"Leith")), row.names = c(NA, -20L), class = c("tbl_df", "tbl",
"data.frame"))
不确定这是否是显示数据框的正确方法,如果有误请告诉我更好的方法。 id 喜欢显示数据框中社区的前 5 个中位数价格。 我在这里显示了数据框中的几行,但还有更多。 我用来获取每个社区中位数的代码是:
edibnb %>%
count(neighbourhood, sort = TRUE)
但是我不知道如何只显示前 5 名。非常感谢!
这就是你要找的?
edibnb %>%
group_by(neighbourhood) %>%
summarise(med_price = median(price), .groups = "drop") %>%
top_n(n = 5, med_price)
neighbourhood med_price
<chr> <dbl>
1 New Town 102.
2 Newington 280
3 Old Town 71
4 Southside 108.
5 West End 170
基础 R:
med_price <- aggregate(price ~ neighbourhood, edibnb, median)
med_price[order(-med_price$price), ][1:5, ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.