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 7961265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:59:37+00:00 2026-06-04T04:59:37+00:00

Suppose I have an R vector of unique elements such as x <- c(1,2,3,4,5)

  • 0

Suppose I have an R vector of unique elements such as x <- c(1,2,3,4,5).

Is there a function to give me a list of all possible partitions of this vector x? I guess each partition would be a list of vectors, where each element in x belongs to one of the vectors. I want all possible partitions into any number of sets of any size.

(I think the number of such partitions is something like 2^n * n!, where n is the number of unique elements. I will probably not be using this function on vectors with more than 4 unique elements.)

  • 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-04T04:59:38+00:00Added an answer on June 4, 2026 at 4:59 am

    Here’s a solution that will get you a complete list of partitions, each one of which is represented as a list of vectors. Since a list of lists is pretty ugly when printed to the screen, I’ve also shown you how to get a more nicely printed object.

    library(partitions)
    
    x <- c(2,4,6)       # Substitute the vector for which you want partitions 
    parts <- listParts(length(x))
    out <- rapply(parts, function(ii) x[ii], how="replace")
    
    # This step is for cosmetic purposes only. It allows you to take advantage of
    # the `print.equivalence` print method when printing the object to a console 
    for(i in seq_along(out)) class(out[[i]]) <- c("list", "equivalence")
    out
    [[1]]
    [1] (2,4,6)
    
    [[2]]
    [1] (2,6)(4)
    
    [[3]]
    [1] (2,4)(6)
    
    [[4]]
    [1] (4,6)(2)
    
    [[5]]
    [1] (2)(4)(6)
    

    See also setparts() in the same package for a more compact way to represent the same set of partitions.

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

Sidebar

Related Questions

Suppose I have a vector<int> myvec and I want to loop through all of
Suppose I have this (C++ or maybe C) code: vector<int> my_vector; for (int i
Suppose you have a function 'normalize' which takes a list of numbers (representing a
Please suppose I have a function that accepts a pointer as a parameter. This
Suppose I have two containers of elements: std::vector<std::string> foo = { aa, bb, cc
Suppose I have a function f that takes a vector v and returns a
suppose I have this vector vector<Object> m; and then I have the following assignments:
I have a vector v1 (suppose v1= a1,b2,c1 ) and this v1 passes through
Suppose I have the following function: void foo(std::vector<int> vec, int n); If I call
Suppose I have a matrix such that each row is a standard basis vector,

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.