Message Boards Message Boards

0
|
4682 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Split list into exactly 4 parts/sublists using Multicolumn[] function?

Hello,

I have a list {1,2,3,4,5} and I need split this into exactly 4 parts/sublists. One approach was to use Multicolumn[] function. Check this program.

Table[Multicolumn[{1, 2, 3, 4, 5}, n], {n, 1, 5, 1}]

For n=3 and n=4, its resulting in the same output. However, I am expecting the program to split it into 4 columns. Kindly help.

Multicolumn Function Error

POSTED BY: Manjunath Babu
3 Replies

Column does the follow 'calculation': Let's say you have n elements and you request c columns:

rows = Ceiling[n/c]

so in your case Ceiling[5/4]=2 rows. So it start creating each column by taking 2 elements each time:

{{1,2},{3,4},{5}} 

which is 'transposed' and then shown in a grid.

POSTED BY: Sander Huisman

I'm also not sure how you would expect it to outcome for the case of 4?

1345
2

would be very weird! One would put it in a grid like that:

135
24

reads more naturally...

POSTED BY: Sander Huisman

The number of columns depends on the number of data in you list. The 5th column exist , it is just empty because in your dataset does not produce enough points to fill the column. Look at this

Table[Multicolumn[{1, 2, 3, 4, 5}, n], {n, 1, 5, 1}]
Table[Multicolumn[{1, 2, 3, 4, 5, 6}, n], {n, 1, 5, 1}]
Table[Multicolumn[{1, 2, 3, 4, 5, 6, 7}, n], {n, 1, 5, 1}]
Table[Multicolumn[{1, 2, 3, 4, 5, 6, 7, 8}, n], {n, 1, 5, 1}]
POSTED BY: Jose Calderon
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract