如果n Obs <n,则删除重复的obs数据. R中的x [英] Removing repeated obs data if n Obs < x in R

查看:248
本文介绍了如果n Obs <n,则删除重复的obs数据. R中的x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个重复测量数据集.我需要删除该个人的观察次数少于3的所有参与者.最佳方法是什么?

I have a repeated measures data set. I need to remove all Participants where the number of observations for that individual is less than 3. What is the best way to do this?

x <- c(9, 9, 9, 11, 11, 23, 23, 23, 23, 45, 45, 45, 56, 56)

这里11和56需要从数据中删除. 到目前为止,我已经创建了一个数据框,其中包含所有我想保留的对象,但是不确定如何使用新数据框来操作我的数据集.

Here 11 and 56 need to be removed from the data. So far I have created a data frame with all the obs that I want to keep but not sure how to manipulate my data set using the new data frame

x <- as.data.frame(table(x))
x1 <- x[x$Freq > 2,]

推荐答案

ave()函数的另一个功能:

x[ave(x,x,FUN=length) > 2]

在回答您的评论时,您应该这样执行:

In an answer to your comment, you should perform it like this :

raw.data1 <- raw.data[ave(raw.data$REGISTRA,raw.data$REGISTRA,FUN=length) > 2]

还请阅读ave的帮助页面,该页面将帮助您了解代码的确切作用.

Also read the help page of ave, that will help you understand what the code is doing exactly.

这篇关于如果n Obs <n,则删除重复的obs数据. R中的x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆