0

Let's say there are two data frames as followed:

test.df1 <- data.frame(id = c(1:5), nr = rnorm(5))
test.df2 <- rbind(test.df1, data.frame(id = c(6:8), nr = rnorm(3)))

Obviously, test.df2 has 3 rows of data, which are not present in test.df1. How can I quickly pick up these additional data. The end effect I wish to have is to obtain a data frame, which contains the 3 rows that are only contained in test.df2. Any help will be appreciated!

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Vincent
  • 87
  • 1
  • 7

1 Answers1

0

Assuming you want nr values that are only present in test.df2 and not in test.df1. You can try

test.df2[!test.df2$nr %in% test.df1$nr, ]

#   id         nr
#6  6 -0.3708036
#7  7 -0.4739193
#8  8  0.3420794
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213