[R] combine two dataframe
Greg Snow
Greg.Snow at intermountainmail.org
Thu Nov 15 18:04:51 CET 2007
Here is another approach:
> tmp <- expand.grid( 1:nrow(B), 1:nrow(A) )
> out <- cbind( A[tmp[,2],], B[tmp[,1],] )
Hope this helps,
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of sun
> Sent: Tuesday, November 13, 2007 4:50 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] combine two dataframe
>
> I have two data frame A and B adn want to cross them.
> A has format as:
>
> a1 a2 a3
> 1 2 3
> 2 3 1
> 1 3 2
> ...
>
> B:
>
> b1 b2
> 1 2
> 2 1
> ...
>
> the combine result shall be something like
>
> a1 a2 a3 b1 b2
> 1 2 3 1 2
> 1 2 3 2 1
> 2 3 1 1 2
> 2 3 1 2 1
> 1 3 2 1 2
> 1 3 2 2 1
> ....
>
>
> is there a function able of doing this instead of loops?
>
> Thanks,
> Sun
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list