合并两个变量以创建频率表
我还有一个新手问题;
假设我有一组数字
graph_val <- c(4,2,3,4,1,1,9)
,我需要根据这个比例创建它们的频率表
1 2 3 4 5 9
"Very Poor" "Poor" "Average" "Good" "Very Good" "Don't Know"
本质上我想知道的是如何将表格转换为这种格式:
"Very Poor" "Poor" "Average" "Good" "Very Good" "Don't Know"
2 1 1 1 0 1
或者至少:
1 2 3 4 5 9
2 1 1 1 0 1
我可以添加标签稍后将 name.arg 与 barplot 2 一起使用。
我已经在这一天的大部分时间里都在做这件事,之后我的自动化工作的其余部分就一帆风顺了。我认为我在制表方面走在正确的轨道上,但无法完全实现目标。
I have another newbie question;
lets say I have a set of numbers
graph_val <- c(4,2,3,4,1,1,9)
and I need to create a frequency table of them against this scale
1 2 3 4 5 9
"Very Poor" "Poor" "Average" "Good" "Very Good" "Don't Know"
Essentially what I want to know is how do I get a table into this format:
"Very Poor" "Poor" "Average" "Good" "Very Good" "Don't Know"
2 1 1 1 0 1
or at the very least:
1 2 3 4 5 9
2 1 1 1 0 1
And I can add the labels in later using names.arg with barplot 2.
I've been on this for most of the day, after this its clear sailing for the rest of my automation job. I thought I was on the right track with tabulate but couldn't quite get there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要考虑数据。完全按照考虑分类变量的方式来考虑因素。级别告诉它会发生什么,标签给它一个漂亮的名字。
如果你需要百分比,你可以这样做:
或者这样:
First you need to factor your data. Think of a factor exactly in the way that you would think of a categorical variable. Levels tells it what to expect, labels gives it a pretty name.
If you need percentages, you can do something like this:
Or this:
“R 简介”中的以下内容直接回答了您的问题:
http://cran.r-project.org/doc/manuals/R-intro.html#Frequency-tables-from-factors
The following from "An Introduction to R" directly answers your question:
http://cran.r-project.org/doc/manuals/R-intro.html#Frequency-tables-from-factors