Ah! I like the idea. Thanks!
jholtman wrote:
>
> Missed that you wanted to elim duplicated:
>
>> z <- expand.grid(test,test)
>> # add 'unique' key
>> z$key <- apply(z, 1, function(x)paste(sort(x), collapse=''))
>> str(z)
> 'data.frame': 16 obs. of 3 variables:
> $ Var1: Factor w/ 4 level
Reading ?expand.grid, there is a "see also" reference to "combn" which looks
close to what you want.
---
Jeff Newmiller The . . Go Live...
DCN: Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research En
On Jul 5, 2011, at 7:16 PM, Q wrote:
Hello,
I'm trying to create a data frame where each row has a unique
combination of
factors.
I start with a vector of species like so:
1> test <- c("A","B","C","D")
1> test
[1] "A" "B" "C" "D"
To get all species combinations I have used expand.grid l
Missed that you wanted to elim duplicated:
> z <- expand.grid(test,test)
> # add 'unique' key
> z$key <- apply(z, 1, function(x)paste(sort(x), collapse=''))
> str(z)
'data.frame': 16 obs. of 3 variables:
$ Var1: Factor w/ 4 levels "A","B","C","D": 1 2 3 4 1 2 3 4 1 2 ...
$ Var2: Factor w/ 4 l
Is this what you want:
> test <- c("A","B","C","D")
> expand.grid(test,test)
Var1 Var2
1 AA
2 BA
3 CA
4 DA
5 AB
6 BB
7 CB
8 DB
9 AC
10BC
11CC
12DC
13AD
14BD
15CD
16DD
Hello,
I'm trying to create a data frame where each row has a unique combination of
factors.
I start with a vector of species like so:
> 1> test <- c("A","B","C","D")
>
> 1> test
>
> [1] "A" "B" "C" "D"
>
To get all species combinations I have used expand.grid like this:
> 1> pairs <-
6 matches
Mail list logo