Minitab Cookbook
上QQ阅读APP看书,第一时间看更新

Stacking several columns together

Minitab will prefer data set up as columns, and often, it is better to stack data together, using one column for all the results, and a second or third column to group the information together. Here, we will stack several numeric columns together into one column.

Getting ready

We want to stack several columns together to give a column of results and an indicator column to identify the group they belong to.

We require a worksheet with several columns of the same data type. In this example, we use data from the Party Membership of US Senators file. This data can be found at

http://mathforum.org/workshops/sum96/data.collections/datalibrary/data.set6.html.

This data is in the Excel file format. Download the file senators.xls. If you are copying and pasting data into Minitab, copy lines 3 to line 53. Alternatively, when following the instructions in the Opening an Excel file in Minitab recipe, set row 3 for the variable names.

The first column should be named State. Ensure that in Minitab the data appears as shown in the following screenshot:

Getting ready

How to do it…

The following instructions will stack the party columns together to create a single column for the number of US Senators:

  1. Go to the Data menu and select Stack; then click on Columns.
  2. Select the numeric columns, Democrats, Republicans, and Independents from the left-hand selection. They can be double-clicked on across into the section Stack the following columns:, alternatively select column 2 and drag down to column 4. Then click on the Select button to move the columns as a group.
    How to do it…
  3. Name the worksheet Stacked Data, from the New Worksheet section and click on OK.
  4. The worksheet will appear as in the following screenshot. As the columns will not be named from the stack command we need to rename them in the new worksheet. Column 1 Subscripts should be renamed to Party, and column 2 should be renamed to Senators.
    How to do it…

The preceding screenshot shows the stacked results that are created in a new worksheet. A useful tip here to avoid confusion while generating new worksheets, is to name the worksheet that will be generated in the stack column's dialog box.

How it works…

By default, the columns are created in a new worksheet, and an additional subscript column is created to differentiate the groups in the data. This can be deselected and will identify the stacked data by numeric values: 1 for the first column, 2 for the second, and so on. Alternatively, the data can be stacked into the same worksheet.

See also

  • The Stacking blocks of columns at the same time recipe
  • The Transposing the columns of a worksheet recipe