0

I have the following list and data.frame .

 rows_i_need = c(letters)
 df1 = data.frame(a=c("a", "b", "c", "e", "f", "g", "i", "j", "k"), 
      b=rnorm(9, 6, 2), 
      c=rnorm(9, 12, 3.5), 
      d=rnorm(9, 8, 3)
      )

How can I create a new list of the 'missing rows', so with output list:

 missing_rows = c("d", "h", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
Sylvia Rodriguez
  • 1,203
  • 2
  • 11
  • 30

2 Answers2

1

You could use this...

missing_rows = rows_i_need[!rows_i_need %in% df1$a]

CallumH
  • 751
  • 1
  • 7
  • 22
1

I would suggest an approach with match():

rows_i_need[-match(df1$a,rows_i_need)]

Output:

[1] "d" "h" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
Duck
  • 39,058
  • 13
  • 42
  • 84