Jump to content

Recommended Posts

Posted (edited)

Hello, I am doing a project in R and am interested in creating a list of vectors of TRUES and FALSES as follows:

FALSE FALSE FALSE FALSE FALSE
FALSE FALSE FALSE FALSE TRUE
FALSE FALSE FALSE TRUE FALSE
FALSE FALSE FALSE TRUE TRUE
...
TRUE TRUE TRUE TRUE TRUE

I have manually typed all 32 combinations; however, I am interested in doing this more elegantly. I imagine a loop and some sort of modulus operation are required. Any advice would be appreciated.

Thank you!

Edited by FancyJules
Posted

Make 2 copies of the list you have of 32 combinations. Prefix one set with "True" and the other set with "False".

You now have a list of 64

Make 2 copies of that list...

Posted

Yes, you can use logic test and assign the results to a vector:

 

a<- c()

a[1]<- 3>4

 

You can loop or use something like which() to do this more cleverly depending on your test.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.