如何在数据框架中获得特定值的重量?
我有一个数据框架,其中包括不同公司的员工回应。响应分为Yes = 1否= 2。我想知道每家公司是(1)的百分比。
Company <- (a,a,b,b,b,c,c)
Response <- (1,1,2,2,1,1,2)
这是我想要的结果
"yes" answers
company a 100%
company b 33%
company c 50%
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在基础中,您可以做:
什至:
In base R you can do:
or even:
您可以使用DPLYR包装来实现此目标。
只需记住:在R中,字符串在引号之间。
您需要将这两个向量放在桌子中。 (使用
data.frame()
在2022-06-17创建的(v2.0.1)
you can achieve this with the dplyr package.
Just keep in mind: in R, strings are between quotes.
You need to put these two vectors together in a table. (created with
data.frame()
Created on 2022-06-17 by the reprex package (v2.0.1)
尝试一下
Try this