Just use vect_2_id as a subsetting index for vect_1, ie: vect_2<-vect_1[vect_2_id]
Vincy Pyne wrote: > > Dear R helpers > > Suppose I have a vector as > > vect_1 = c("AAA", "AA", "A", "BBB", "BB", "B", "CCC") > > vect_1_id = c(1:length(vect_1)) > > Through some process I obtain > > vect_2_id = c(2, 3, 7), then I need a new vector say vect_2 which will > give me > > vect2 = ("AA", "A", "CCC") i.e. I need the subset of vect_1 as per > vect_2_id. > > Thanking in advance > > Regards > > Vincy > > > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- View this message in context: http://r.789695.n4.nabble.com/Matching-two-vectors-tp3357591p3357603.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.