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

2014-11-14 Thread MacQueen, Don
Sorry, I was too quick. Try A[ match(B, A$ID2) ,] -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/14/14, 1:45 PM, "Pedro Mardones" wrote: >Dear R user; > >Consider the following toy example > >A <- data.frame(ID1 = c(1

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

2014-11-14 Thread Rolf Turner
On 15/11/14 10:45, Pedro Mardones wrote: 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 wan

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

2014-11-14 Thread MacQueen, Don
Try B <- c("a", "a", "a", "h", "b", "e") subset(A, ID2 %in% B) or subset(A, ID2 %in% unique(B)) will do as well -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/14/14, 1:45 PM, "Pedro Mardones" wrote: >Dear R user; >