[R] questions on data management
Jacques VESLOT
jacques.veslot at good.ibl.fr
Thu Jul 6 13:26:49 CEST 2006
mnu <- unique(mn[order(mn$m,mn$n),])
mnu$p <- table(paste(mn$m, mn$n))
merge(mnu[sample(1:nrow(mnu), size=3, prob=mnu$p, replace=F), c("m","n")], 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!
>
>
>
>
More information about the R-help
mailing list