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
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
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
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
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
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
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.
7 matches
Mail list logo