[R] select same row in a data frame several times

Pedro Mardones mardones.p at gmail.com
Fri Nov 14 22:45:40 CET 2014


Dear R user;

Consider the following toy example

A <- data.frame(ID1 = c(1,2,3,1,2,3,1,2,3), ID2 =
c("a","b","c","d","e","f","g","h","i"), stringsAsFactors = FALSE)
B <- sample(a$ID2, 6, replace = TRUE)

Lets say B is = "a", "a", "a", "h", "b", "e"

I want to extract from A the rows where ID2 == B. If I use
AA <- A[A$ID2 %in% B == TRUE,], I get only 1 row with ID2="a" instead of
the 3 rows I want.

Is it possible to easily implement this selection? (same row several times)

Thanks
Pedro

	[[alternative HTML version deleted]]



More information about the R-help mailing list