[R] Puzzled at generating combinations

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Tue Mar 18 17:15:54 CET 2008


> I have two data frames. Suppose the first has rows
> 
> r1
> r2
> r3
> 
> and the second has rows
> 
> R1
> R2
> R3
> 
> I'd like to generate the data frame:
> 
>     r1   R1
>     r1   R2
>     r1   R3
>     r2   R1
>     r2   R2
>     r2   R3
>     r3   R1
>     r3   R2
>     r3   R3

Try:
col1 <- paste("r", 1:3, sep="")
col2 <- paste("R", 1:3, sep="")
data.frame(rep(col1, each=3), rep(col2, times=3))

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}



More information about the R-help mailing list