R的纵向排除R

发布于 2025-02-09 01:13:54 字数 279 浏览 2 评论 0原文

我有一个宽格格式的大数据集,其中我从不同的时间点(W1,W2,W3 ...)和一个ID列中有9个数据波。我想排除仅在1个时间点或0个时间点上数据的参与者。 之前,我已经有条件地将参与者排除在以下代码中:

Result <- Merged[!(Merged$w1exclude >1),]

但是,我不确定如何调整代码以将W1-W9变量包含在其中9或8具有Na的情况下。

这是我在这里的第一篇文章,我对R的新手很抱歉,如果在我现在知道的其他地方回答了这一点。

I have a large dataset in wide format where I have 9 waves of data from different timepoints (w1, w2, w3...) and an ID column. I want to exclude participants who only have data on 1 timepoint or 0 timepoints.
Earlier, I have excluded participants conditionally with the following code:

Result <- Merged[!(Merged$w1exclude >1),]

However, I am unsure how to adapt the code to include the w1-w9 variables on the condition that 9 or 8 of them have NA's.

This is my first post here and I am new to R so apologies if this has been answered in a thread elsewhere I am now aware of.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱世争霸 2025-02-16 01:13:54

这个问题可能与 dataframe in ROW 计数NAS

df <- data.frame(w1 = c(1,2,3,4,NA),
                 w2 = c(2,3,NA,4,NA))
rowSums(is.na(df))

[1] 0 0 1 0 2

This question is potentially the same as Count NAs per row in dataframe

df <- data.frame(w1 = c(1,2,3,4,NA),
                 w2 = c(2,3,NA,4,NA))
rowSums(is.na(df))

[1] 0 0 1 0 2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文