我有以下问题。我希望每个房间类型显示平均价格,但所有行中显示的价格相同,并且表中的级别仍然重复。就好像分组没有发生过一样。
room_type <- c("Entire home/apt","Private room","Shared room","Hotel room","Entire home/apt", "Private room","Shared room","Hotel room")
price <- c(100, 200, 50, 3000, 80, 90, 56, 30)
listing <- data.frame(room_type, price)
print(listing)
df_2 <- listing %>%
group_by(room_type) %>%
mutate(price = mean(price)) %>%
summarise(room_type = room_type, avg_price = price)
df_2
1条答案
按热度按时间z9smfwbn1#
这是你要找的吗?
这是结果