【发布时间】:2018-12-04 19:14:58
【问题描述】:
想象一下,我的朋友根据我的预算向我推荐了一些汽车。对于每个预算,我想确定所有朋友推荐相同品牌的次数以及所有朋友推荐相同品牌和型号的次数。
budget <- c(rep(c("broke", "modest", "dreaming"), each = 3), rep("broke", 3))
friend <- (rep(c("mark", "mary", "monelle"), 4))
make <- c(rep("ford", 3), rep("honda", 3), "porche", rep("bmw",2), rep("bicycle", 3))
model <- c(rep("fiesta", 3), rep("civic", 2), "tacoma", "911", "i3", "Z4", rep("used", 3))
df <- data.frame(budget, friend, make, model)
budget friend make model
1 broke mark ford fiesta
2 broke mary ford fiesta
3 broke monelle ford fiesta
4 modest mark honda civic
5 modest mary honda civic
6 modest monelle honda tacoma
7 dreaming mark porche 911
8 dreaming mary bmw i3
9 dreaming monelle bmw Z4
10 broke mark bicycle used
11 broke mary bicycle used
12 broke monelle bicycle used
期望的输出 -
budget matchMake matchMake+Model
broke 2 2
modest 1 0
dreaming 0 0
【问题讨论】:
-
为更新的示例添加所需的输出。
-
希望这有意义吗?感谢您的帮助!
-
您的 reprex 输入未遵循您的预期结果 - 如果您正在寻找更多答案,请确保您的 reprex 从头到尾都有意义。至于问题,看
dplyr::count -
您的问题含糊不清。您是什么意思“我的朋友告诉我购买同一辆车的频率”?如果有人告诉您一次购买相同的品牌,那是 0 还是 1?如果他们告诉你两次,是 1 还是 2?