Question about permutation and combinations

r

Hello,

I am trying to learn about permutations and combinations in rstudio
I have an idea of what am trying to achieve. Considering 13 sports games with n = 13, where there are r = 3 possible outcome HW, D, AW.

R code

s <- c("HW", "D", "AW")
permutation(n = 13, r = 3,v=s, repeats.allowed = F ))

I get an error;

Error: unexpected ')' in "permutations(n=13,r=3,v=s,repeats.allowed=F ))"
 v is either non-atomic or too short

I want to get the combinations, but most importantly, i want to list the possible combinations in the data set.
I am new to programming, i will appreciate your help on this problem.

What package is the permutation function from?

The Error: unexpected message is because you have an unmatched closing parenthesis. The code should be:

permutations(n=13,r=3,v=s,repeats.allowed=F)

Thank you
Although, i still get the same error.
I've also tried this
x <- c("HW", "DD", "AW")

permutations(n=13,r=3,v=x)
But the error still is:
v is either non-atomic or too short

Hi nwerth. The script should n = Size of the source vector and r = Size of the target vectors.

s <- c("HW", "D", "AW")
gtools::permutations(3, 13, s, repeats.allowed = TRUE)
2 Likes

This does solve it, thank you raytong

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.