merge(mn[sample(1:nrow(mn), 3, rep=F),], xy, by.x=c("m","n"), by.y=c("x","y")) ------------------------------------------------------------------- Jacques VESLOT
CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr ------------------------------------------------------------------- zhijie zhang a écrit : > Dear friends, > suppose i have two datasets: A and B > A: > id<-1:6 > x<-c(1,2,3,4,5,6) > y<-c(2,4,6,8,3,2) > xy<-data.frame(id,x,y) > B > m<-c(1,1,3,3,5,5) > n<-c(2,2,6,6,3,3) > mn<-data.frame(m,n) > Now, i want to perfomr two tasks: > 1. get a subset of B,no duplicate values,: > C: > m n > 1 2 > 3 6 > 5 3 > > 2.Extract the values in A on the conditions that x=m and y=n > the results should be: > id x y > 1 1 2 > 3 3 6 > 5 5 3 > Thanks very much! > > > > ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html