Hi all, i have a little pb but i don t find how i can solve it.. this is.. i have two vectors x and yn and they don t have the same length... (i suppose length(x)>length(y)) this is what i want to do. i suppose that x=c(10,1,2,3,7,9,1,4,2,11,2,10) and y=c(1,2,4,10) i want to find all the numbers of rows i of x for which x[i] exists in y ... i.e. in this case ...rep=(1,2,3,7,8,9,11,12) Best regards, Olivier -- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- Olivier MARTIN phone: (33) 04 76 61 53 55 Projet IS2 06 08 67 93 42 INRIA Rhone-Alpes fax : (33) 04 76 61 54 77 655, Av. de l'Europe Montbonnot e-mail:olivier.martin at inrialpes.fr 38334 Saint Ismier cedex -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20010426/df9eddea/attachment.html
On Thu, 26 Apr 2001, Olivier Martin wrote:> Hi all, > > i have a little pb but i don t find how i can solve it.. > this is.. > i have two vectors x and yn and they don t have the same length... > (i suppose length(x)>length(y)) > this is what i want to do. > i suppose that > x=c(10,1,2,3,7,9,1,4,2,11,2,10) and y=c(1,2,4,10) > i want to find all the numbers of rows i of x for which x[i] exists in y > ... > i.e. in this case ...rep=(1,2,3,7,8,9,11,12) >which(x %in% y) -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 26 Apr 2001, Olivier Martin wrote:> i have two vectors x and yn and they don t have the same length... > (i suppose length(x)>length(y)) > this is what i want to do. > i suppose that > x=c(10,1,2,3,7,9,1,4,2,11,2,10) and y=c(1,2,4,10) > i want to find all the numbers of rows i of x for which x[i] exists in y > ... > i.e. in this case ...rep=(1,2,3,7,8,9,11,12) >Something like:> x <- c(10,1,2,3,7,9,1,4,2,11,2,10) > y <- c(1,2,4,10) > x %in% y[1] TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE> which(x %in% y)[1] 1 2 3 7 8 9 11 12 You could do it with match() too. Roger -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Breiviksveien 40, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93 e-mail: Roger.Bivand at nhh.no and: Department of Geography and Regional Development, University of Gdansk, al. Mar. J. Pilsudskiego 46, PL-81 378 Gdynia, Poland. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._