Re: [R] Create a data frame of all possible unique combinations of factors

2011-07-05 Thread Q
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

Re: [R] Create a data frame of all possible unique combinations of factors

2011-07-05 Thread Jeff Newmiller
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

Re: [R] Create a data frame of all possible unique combinations of factors

2011-07-05 Thread David Winsemius
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

Re: [R] Create a data frame of all possible unique combinations of factors

2011-07-05 Thread jim holtman
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

Re: [R] Create a data frame of all possible unique combinations of factors

2011-07-05 Thread jim holtman
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

[R] Create a data frame of all possible unique combinations of factors

2011-07-05 Thread Q
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 <-