Re: [R] Writing a Permutation Function

2012-04-29 Thread petermec
Thanks for all the suggestions. This is my final code that seems to be working: alphabet = c("a","b","c","d") holder = c() permute = function(alphabet,n){ while((length(unique(holder))/n)<(length(alphabet)^n)){ perm = sample(alphabet, replace=T, size=n) holder = rbind(holder, perm, deparse

Re: [R] Writing a Permutation Function

2012-04-28 Thread R. Michael Weylandt
It's _highly_ inefficient to grow the "holder" each step of the loop -- you'll see massive speedups by setting something like holder = character(4000) # Make an empty character vector of length 4000 # inside the loop just fill the part you're looking at holder[i:(i+3)] = perm Michael On Sat, Ap

Re: [R] Writing a Permutation Function

2012-04-28 Thread petermec
Thanks for the input everyone! So far this is the updated code that I have: alphabet = c("a","b","c","d") holder = c() permute = function(alphabet,n){ for (i in 1:1000){ perm = sample(alphabet, replace=F, size=n) holder = rbind(holder, perm, deparse.level=0) } data2 = unique(holder) data3

Re: [R] Writing a Permutation Function

2012-04-28 Thread David Winsemius
On Apr 28, 2012, at 9:18 AM, mlell08 wrote: On Apr 28, 2012, at 8:11 AM, petermec wrote: Hi everyone, I am somewhat new to R and I am trying to write a permutation function such that it inputs a character vector and from an arbitrary length "n" which is the length of the combinations f

Re: [R] Writing a Permutation Function

2012-04-28 Thread mlell08
On 28.04.2012 14:47, Sarah Goslee wrote: > We really can't help you with your assignment. You might consider > ??unique > though, since you've already resolved to look for functions related to > identifying unique entries. > > Sarah > > On Apr 28, 2012, at 8:11 AM, petermec wrote: > >> Hi everyon

Re: [R] Writing a Permutation Function

2012-04-28 Thread Sarah Goslee
We really can't help you with your assignment. You might consider ??unique though, since you've already resolved to look for functions related to identifying unique entries. Sarah On Apr 28, 2012, at 8:11 AM, petermec wrote: > Hi everyone, > > I am somewhat new to R and I am trying to write

[R] Writing a Permutation Function

2012-04-28 Thread petermec
Hi everyone, I am somewhat new to R and I am trying to write a permutation function such that it inputs a character vector and from an arbitrary length "n" which is the length of the combinations for the character vector. I know there are R packages for permutation but this is for an assignment.