This article describes how to go from a multiple-column table with more than one statistic and nested data...
...to return only the cells you need.
Requirements
A multiple-column table with multiple statistics and nested data created by including a Nominal-Multi question as the Row question used in your table. If you're using a table with a nested banner, please see How to Work with Nested Banners and Spans in R Tables.
Method 1 - Point and click
1. Click on Calculation > Custom Code from the toolbar.
2. Click on the page to insert a calculation box on the page.
3. While the cursor is blinking (active) in the R Code editor, click on a part of a table that you'd like to extract.
See Bespoke Analyses for examples and a demo of the feature. Note:
- if you are using a table with multiple statistics, you will need to reference the specific statistic that you would like to use in the output using code. For example, the table above contains the column % and count statistics. If I want to reference the Hate - Male, Hate - Female columns, all rows, and include the column % statistic, I will need to modify the R code to be:
table.Q4.Brand.Attitude.by.Gender[, 1:2, ,1]
- if you are using point-and-click with a nested banner, you must use the banner numbers and not the column label, since it is repeated.
Method 2 - By name
1. Select your table.
2. Copy the name from General > GENERAL > Name.
3. Click on Calculation > Custom Code from the toolbar.
4. Click on the page to insert a calculation box on the page.
5. In the R Code editor, you can check the table dimensions. Write dimnames(table_name)
using the name from step 2 and you will return a list of names for each dimension of your table:
6. Using this definition, we need to add a line in the format of table_name[row_name, column_name, nested_column_name, statistic_name]
Using our example, the code to return just the percentage for females who love Coca-Cola is:
table.gender.brand.attitude["Coca-Cola","Love","Female","Column %"]
To instead return percentages for everyone who likes or loves Coca-Cola is:
table.gender.brand.attitude["Coca-Cola",c("Like","Love"),,"Column %"]
Leaving one of these arguments empty will return all the rows, columns, or statistics respectively from the table.
Below the Hate - Love argument has been removed from above so it returns all ratings:
7. OPTIONAL: Add a percentage sign or adjust the number of decimal places via Appearance > Appearance > Number format.
Method 3 - By index
1. Select your table.
2. Copy the name from General > GENERAL > Name.
3. Click on Calculation > Custom Code from the toolbar.
4. Click on the page to insert a calculation box on the page.
5. In the R Code editor, using the definition from Method 2 Step 6, we need to add a line in the format of table_name[row_index, column_index, nested_column_index, statistic_index]
Using our example, the code to return the percentage the percentage for females who love Coca-Cola is: table.gender.brand.attitude[1,5,2,1]
To instead return percentages of everyone who likes or loves Coca-Cola is: table.gender.brand.attitude[1,c(4,5),,1]
Alternatively, you can use index ranges, whereby the above can also be written as: table.gender.brand.attitude[1,c(4:5),,1]
You can even reverse this to remove the other ratings instead: table.gender.brand.attitude[1,c(-1:-3,-6),,1]
You can additionally keep only the last cola category by using the NROW argument:
table.gender.brand.attitude[NROW(table.gender.brand.attitude),,,]
6. OPTIONAL: Add a percentage sign or adjust the number of decimal places via Appearance > Appearance > Number format.
Next
How to Work with Nested Banners and Spans in R Tables
How to Extract Data from a Single Column Summary Table
How to Extract Data from a Multiple Column Table
How to Extract Data from a Multiple Column Table with Multiple Statistics