I have two data sets and both contain "ID" variable. In both data sets, How I can remain observations that ID exist in both data sets ? I am using R.
Such as
df1 <- structure(list(CustomerId = c(1, 2, 3, 4, 5, 8, 9), Product = structure(c(4L,
4L, 4L, 3L, 3L, 1L, 2L), .Label = c("abc", "def", "Radio", "Toaster"
), class = "factor")), .Names = c("CustomerId", "Product"), row.names = c(NA,
-7L), class = "data.frame")
df2 <-
structure(list(CustomerId = c(2, 4, 6, 7), State = structure(c(2L,
2L, 3L, 1L), .Label = c("aaa", "Alabama", "Ohio"), class = "factor")), .Names = c("CustomerId",
"State"), row.names = c(NA, -4L), class = "data.frame")
In two data sets, I want to remain observations that exist in both data. (Those would be ID 2 and 4 in both data sets.)