R 中频率表的摘要?
我有一组用户建议
review=matrix(c(5:1,10,2,1,1,2), nrow=5, ncol=2, dimnames=list(NULL,c("Star","Votes")))
,想要使用 summary(review)
来显示基本属性平均值、中位数、四分位数和最小值最大值。
但它返回了两列的摘要。我避免使用 data.frame
因为因素“Star”是有序的。 我如何告诉 R Star 是一个因素的有序列表数字分数,而投票是它们的频率?
I have a set of user recommandations
review=matrix(c(5:1,10,2,1,1,2), nrow=5, ncol=2, dimnames=list(NULL,c("Star","Votes")))
and wanted to use summary(review)
to show basic properties mean, median, quartiles and min max.
But it gives back the summary of both columns. I refrain from using data.frame
because the factors 'Star' are ordered.
How can I tell R that Star is a ordered list of factors numeric score and votes are their frequency?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 Star 应该是一个有序因子,我不太确定你所说的一般平均值是什么意思。但是,在您给出的示例中,Star 实际上是一组数值,您可以使用以下内容:
I'm not exactly sure what you mean by taking the mean in general if Star is supposed to be an ordered factor. However, in the example you give where Star is actually a set of numeric values, you can use the following:
我不明白有什么问题。为什么不应该使用
data.frame
?您应该将
data.frame
转换为向量:然后进行摘要...我只是不知道什么样的摘要,因为
summary
会将您带回到开始。 O_o编辑 (根据@Prasad的建议)
由于
vts
是一个有序因子,您应该将其转换为数字,从而计算摘要(此时此刻我将忽略背景统计问题):I don't understand what's the problem. Why shouldn't you use
data.frame
?You should convert your
data.frame
to vector:Then do the summary... I just don't know what kind of summary, since
summary
will bring you back to the start. O_oEDIT (on @Prasad's suggestion)
Since
vts
is an ordered factor, you should convert it to numeric, hence calculate the summary (at this moment I will disregard the background statistical issues):只是为了澄清——当你说你想要“平均值、中位数、四分位数和最小/最大”时,你是在谈论星星的数量吗?例如平均值 = 4.062 颗星?
然后使用 aL3xa 的代码,像
summary(as.numeric(as.character(vts)))
这样的东西会是你想要的吗?Just to clarify -- when you say you would like "mean, median, quartiles and min/max", you're talking in terms of number of stars? e.g mean = 4.062 stars?
Then using aL3xa's code, would something like
summary(as.numeric(as.character(vts)))
be what you want?