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.
我有一个重复测量数据集。我需要删除该个人的观察次数少于 3 的所有参与者。执行此操作的最佳方法是什么?
x <- c(9, 9, 9, 11, 11, 23, 23, 23, 23, 45, 45, 45, 56, 56)
这里需要从数据中删除 11 和 56。到目前为止,我已经创建了一个数据框,其中包含我想要保留的所有 obs,但不确定如何使用新数据框操作我的数据集
x <- as.data.frame(table(x)) x1 <- x[x$Freq > 2,]
另一个ave()功能:
ave()
x[ave(x,x,FUN=length) > 2]
在回答您的评论时,您应该像这样执行它:
raw.data1 <- raw.data[ave(raw.data$REGISTRA,raw.data$REGISTRA,FUN=length) > 2]
另请阅读 ave 的帮助页面,这将帮助您了解代码到底在做什么。
x[x %in% names(table(x)[table(x) >=3])]