Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8180357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:11:47+00:00 2026-06-07T00:11:47+00:00

I have a sequence which varies in length e.g. something like: items <- 1:4

  • 0

I have a sequence which varies in length e.g. something like:

items <- 1:4

I want to split it into every possible combination of n number of sets. So say n is two, I want to return:

Set A    Set B
-----    -----
1        2 3 4
1 2      3 4
1 2 3    4
1 3      2 4 

etc. The arrangement within sets doesn’t matter i.e. the set {1, 2, 3} is the same as {2, 1, 3}. Sets cannot be empty.

Best I could come up with (using permn from the package combinat) is:

n <- 2
r <- 1:length(items)
arrangements <- NULL
for (i in 1:(n-1)) {
  A <- r[(1:i)]
  B <- r[-(1:i)]
  arrangements <- c(arrangements, apply(do.call(rbind, permn(1:length(items))), 1, function(z) list(z[A], z[B])))
}

Which is fairly useless because it returns sets that are equal i.e. {1, 2, 3} and {2, 1, 3} and isn’t flexible enough to handle different values of n. Anyone have any ideas how I can do this? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:11:48+00:00Added an answer on June 7, 2026 at 12:11 am

    There is a ‘sets’ package:

    require(sets)
    power_set(1:4)
    sapply( set_power(1:4) , function(x) set_complement(x ,as.set(1:4)) )
    list( Set_A = as.list(set_power(1:4)), 
          Set_B = sapply( set_power(1:4) , function(x) set_complement(x ,as.set(1:4)) ) )
    

    It includes pairings like ( {1,2,3,4}, {} ) which is correct from a set theory viewpoint, but you may want to eliminate them as “degenerate”. (The way is now clear to generalize this to larger N by working recursively on the Set_B result.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sequence of SQL calls, which I want to use to detect
I have a large file which contains sequence of characters like ABCDEabcde.....XYZxyz. Now, I
I have a large file which contains sequence of characters like ABCDEabcde.....XYZxyz. Now, I
I have a sequence with an allowed minimum length of zero in my xsd.
I have a stacked sequence which runs 2 different tests continuously. Lets call them
I have a standardized sequence of code which I used to display topic information
Assume we have a sequence of bytes with header of '807F' which is input
I have two activities in the sequence which in a transactionscope which has isolationlevel
I have an IEnumerable sequence which contains some blocking network operations (replaced with some
I have a sequence of calls that I need to make, all of which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.