0

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.

Sotos
  • 51,121
  • 6
  • 32
  • 66
Jonas L
  • 3
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 21 '22 at 00:12

1 Answers1

0

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

akshaymoorthy
  • 326
  • 1
  • 4
  • Thank you, this worked. I had other variables in the dataset which needed imputing before I could count the NA's per row, but everything is solved now :) – Jonas L Jun 28 '22 at 10:20