Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含大量条目的向量(380)。我想绘制一个值的图表,但要做到这一点,我需要提取每个值的频率。例如,在向量 (1,2,2,3,4) 中,数字 1、3 和 4 出现一次,数字 2 出现两次。我应该怎么做才能获得这些信息?
该功能table是您的朋友:
table
plot(table(myvector))
请注意,如果您想处理输出并进行进一步的操作,可以用 as.data.frame 将其括起来以获取数据帧。
df <- as.data.frame(table(myvector))
编辑添加 正确,您必须创建一个新对象才能对其进行操作,如下面的评论所述。