【发布时间】:2017-10-31 17:16:37
【问题描述】:
在处理原始数据后,我们得到了以下data.frame
ItemID GroupID mentions
1 601 3 1
2 601 4 1
3 611 3 1
4 661 3 1
5 801 3 1
6 821 3 1
6 841 1 3
6 841 2 3
6 841 3 3
6 841 4 3
我有 10000 条这样的记录,我的第一个目标是找出代表所有 4 个 GroupID 的项目。首先,我尝试通过绘图在视觉上做到这一点。
ggplot(item.stats, aes(x=ItemID, y=mentions, fill=GroupID)) +
geom_bar(stat='identity', position='dodge')
对于大型数据集,这看起来不是一件明智的事情。了解有多少项目代表所有组并提及提及的最佳方法是什么?
在上面的例子中,过滤后它应该只有:
ItemID GroupID mentions
6 841 1 3
6 841 2 3
6 841 3 3
6 841 4 3
试图获得有意义的可视化:
test.with.id <- transform(test,id=as.numeric(factor(ItemID)))
ggplot(test.with.id, aes(x=id, y=mentions, fill=GroupID)) +
geom_histogram(stat='identity', position='stack', binwidth = 2)
可能与此类似 How to plot multiple stacked histograms together in R?
【问题讨论】:
-
假设你的数据在
dat1:with(dat1, ave(GroupID, ItemID, FUN = function(x) length(unique(x)))) -
这会删除所有没有所有 GroupID 的行