Dear friends, i have two dataset: A and B A: x y 1 2 3 4 B: m n 1 2 7 8 How to generate datasetC: C: x n 1 2 3 8 i know sas can do it easily, what about R? -- Kind Regards,
C <- cbind(A[, 1], B[, 2]) On 3/23/06, zhijie zhang <epistat at gmail.com> wrote:> Dear friends, > i have two dataset: A and B > A: > x y > 1 2 > 3 4 > > B: > m n > 1 2 > 7 8 > > How to generate datasetC: > C: > x n > 1 2 > 3 8 > i know sas can do it easily, what about R? > > -- > Kind Regards, > > ______________________________________________ > R-help at 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 >-- HTH, Jim Porzak Loyalty Matrix Inc. San Francisco, CA
On 3/23/06, Jim Porzak <jporzak at gmail.com> wrote:> C <- cbind(A[, 1], B[, 2]) > >The result is: [,1] [,2] [1,] 1 2 [2,] 3 8 How to keep x and n as the column title? Linda
C <- cbind(x=A[, 1], n=B[, 2]) linda.s a ?crit :>On 3/23/06, Jim Porzak <jporzak at gmail.com> wrote: > > >>C <- cbind(A[, 1], B[, 2]) >> >> >> >> >The result is: > [,1] [,2] >[1,] 1 2 >[2,] 3 8 >How to keep x and n as the column title? >Linda > >______________________________________________ >R-help at 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 > > >
what is the difference between the two matrix B and C?> Bm n 1 1 2 2 7 8> C <- cbind(x=A[, 1], n=B[, 2]) > Cx n [1,] 1 2 [2,] 3 8 For B, it use 1 and 2 to indicate rows while C use[1,] and [2,] On 3/23/06, Jacques VESLOT <jacques.veslot at cirad.fr> wrote:> C <- cbind(x=A[, 1], n=B[, 2]) > > >
> cbind(a[,1,drop=F],b[,1,drop=F])x n 1 1 1 2 2 2 2006/3/24, linda.s <samrobertsmith at gmail.com>:> On 3/23/06, Jim Porzak <jporzak at gmail.com> wrote: > > C <- cbind(A[, 1], B[, 2]) > > > > > The result is: > [,1] [,2] > [1,] 1 2 > [2,] 3 8 > How to keep x and n as the column title? > Linda > > ______________________________________________ > R-help at 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 >-- ?????? Deparment of Sociology Fudan University
if A, B and C are of matrix class: C <- cbind(x=A[, 1], n=B[, 2]) if A, B and C are of data.frame class: C <- cbind.data.frame(x=A$x, n=B$n) C <- data.frame(x=A$x, n=B$n) linda.s a ?crit :>what is the difference between the two matrix B and C? > > >>B >> >> > m n >1 1 2 >2 7 8 > > >>C <- cbind(x=A[, 1], n=B[, 2]) >>C >> >> > x n >[1,] 1 2 >[2,] 3 8 > >For B, it use 1 and 2 to indicate rows while C use[1,] and [2,] > >On 3/23/06, Jacques VESLOT <jacques.veslot at cirad.fr> wrote: > > >>C <- cbind(x=A[, 1], n=B[, 2]) >> >> >> >> >> > > >
zhijie zhang wrote:> Dear friends, > i have two dataset: A and B > A: > x y > 1 2 > 3 4 > > B: > m n > 1 2 > 7 8 > > How to generate datasetC: > C: > x n > 1 2 > 3 8 > i know sas can do it easily, what about R? >A<-data.frame(x=c(1,3),y=c(2,4)) B<-data.frame(m=c(1,7),n=c(2,8)) C<-data.frame(A[1],B[2]) Using single square brackets extracts just the named vectors. Jim