1

I have a data frame like below. How can I get the row id when all elements are present in a data table.

For example,

Table:

    L001 044 N   004 E   036 NA   NA  NA  NA  NA  NA
    L001 086 N   016 E   016 NA   NA  NA  NA  NA  NA
    L001 092 N   011 E   026 L002 044 N   006 E   022
    L001 056 N   036 E   061 NA   NA  NA  NA  NA  NA

I need to obtain the row id in "Table" when all elements are filled. For example in this example row id is 3 since all columns in "Table" has a value.

Any help is appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
NUdu
  • 173
  • 6

1 Answers1

0

Where df equals:

df = read.table(
  text = "
  L001 044 N   004 E   036 NA   NA  NA  NA  NA  NA
  L001 086 N   016 E   016 NA   NA  NA  NA  NA  NA
  L001 092 N   011 E   026 L002 044 N   006 E   022
  L001 056 N   036 E   061 NA   NA  NA  NA  NA  NA
  "
)

You can do:

rownames(df[complete.cases(df)==TRUE,])

Resulting in:

[1] "3"
User7598
  • 1,658
  • 1
  • 15
  • 28