-1

I have a data frame such as

ID   a     b     c
29   NA    2     NA
11   3     1     1
9    NA    NA    NA

I'd like to pull out the rows that have at least 1 value filled in for all the columns except for the ID. For example, the row with ID=9 would not satisfy that condition, because all the columns after the ID column are NA.

You might think one way would be

d = d[!is.na(d$a) | !is.na(d$b) | !is.na(d$c),]

however in my case, there are like 20 columns after the ID column, not just three.

What's a better way to do this?

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
StanLe
  • 5,037
  • 9
  • 38
  • 41

1 Answers1

2

Something like this?

df[rowSums(!is.na(df[ , -1])) > 0, ]

#   ID  a b  c
# 1 29 NA 2 NA
# 2 11  3 1  1
Henrik
  • 65,555
  • 14
  • 143
  • 159