John Lande
2008-Jun-28 11:38 UTC
[R] mapping one redundant index to another redundant index
Dear R users, I have a simple problem I cannot solve, but I sure you can help. I have two vector, let say> tmp1 <- c("a", "a", "b", "c") > tmp2 <- c("a", "a", "b", "c", "c", "d")and I want to create a matrix of two column for which I have all the combinations of the same character, let say like this> tmp3tmp1 tmp2 [1,] "a" "a" [2,] "a" "a" [3,] "a" "a" [4,] "a" "a" [5,] "b" "b" [6,] "c" "c" [7,] "c" "c" how can I perform this task? thank you! [[alternative HTML version deleted]]
Gabor Grothendieck
2008-Jun-28 15:08 UTC
[R] mapping one redundant index to another redundant index
merge(tmp1, tmp2) gives the basic data and you can put it
in the form requested using:
Tmp1 <- data.frame(x = tmp1)
Tmp2 <- data.frame(x = tmp2)
M <- merge(Tmp1, Tmp2)
data.frame(tmp1 = M$x, tmp2 = M$x)
or using Tmp1 and Tmp2 from above:
library(sqldf)
sqldf("select x tmp1, x tmp2 from Tmp1 natural join Tmp2")
See sqldf home page at:
http://sqldf.googlecode.com
On Sat, Jun 28, 2008 at 7:38 AM, John Lande <john.lande77 at gmail.com>
wrote:> Dear R users,
>
> I have a simple problem I cannot solve, but I sure you can help.
>
> I have two vector, let say
>
>> tmp1 <- c("a", "a", "b",
"c")
>> tmp2 <- c("a", "a", "b",
"c", "c", "d")
>
> and I want to create a matrix of two column for which I have all the
> combinations of the same character, let say like this
>
>> tmp3
> tmp1 tmp2
> [1,] "a" "a"
> [2,] "a" "a"
> [3,] "a" "a"
> [4,] "a" "a"
> [5,] "b" "b"
> [6,] "c" "c"
> [7,] "c" "c"
>
>
> how can I perform this task?
>
>
> thank you!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>