[英]How to summarize data by row and column in R
library(dplyr)
cardata <- data.frame(country = c("poland", "germany", "austria",
"poland","poland", "austria",
"germany","germany"),
car = c("Fiat", "Fiat", "BMW", "Fiat", "BMW",
"Toyota", "Toyota", "Toyota"),
Age = c(5, 4, 2, 6, 6, 2, 1, 8),
Km = c(12e4, 10e4, 22e3, 14e4, 15e4, 52e3, 21e3, 22e4))
cardata %>%
group_by(country, car) %>%
summarise(AvgAge = mean(Age),
AvgKm = mean(Km))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.