This article describes how to perform basic mathematical functions on variables in Displayr using the Calculation menu. There are many benefits to using these functions:
- You don't need to worry about writing code. However, you can still edit the R code used if you need further customization.
- You can perform calculations using partial data (i.e. ignore missing data), if needed.
- You can do bulk calculations across variable sets. That is, the feature will match variables (based on their label) within variable sets and perform the calculation across the matches to create a final variable set with a variable for each calculation. For example, you can have a variable set with the number of drinks for each brand outside the home and another inside the home. Using the function will calculate the sum for each brand of drinks outside + inside the home, and create a variable set with a variable for each brand's sum.
- Conversely to the bullet above, you can also use the "Each Row" version of the calculation to ignore individual variable labels and perform the calculation across all variables in all variable sets selected.
The operations include: Divide, Multiply, Subtract, Average, Sum, Maximum, Minimum, Any of, None of, Count, Standard Deviation, and Variance.
There are a plethora of reasons to use these functions notably:
- Adding up quantity purchased for each respondent for individual items, using Sum.
- Checking that a set of a variables add up to 100% for each respondent, using Sum then creating a filter for those equal to 100%.
- Converting a variable in minutes into hours, using Divide.
- Creating a NET or Total variable based on if a respondent selected any item in a multiple response variable set. Unlike Displayr's built-in NETs and Totals, you can include respondents with missing data in these totals, using Maximum (if the data is binary) or Any of (if there are other values).
- Creating a None of the Above variable based on specific variables, using None of.
For details of each mathematical calculation and options see Mathematical Calculations on Tables and Variables. This article is divided into sections below:
- Method - Divide, Multiply, Subtract
- Method - Average, Sum, Maximum, Minimum, Any of, None of, Count, Standard Deviation, Variance
Requirements
- A Displayr document with a data set.
- Numeric variables. In this example, we have a numeric grid variable set called Q2 - No. of colas consumed which we will use for these calculations:
Method - Divide, Multiply, Subtract
1. Select one or two variables in the Data Sources tree that you wish to use in your calculation. For example, let's select the Coca-Cola - When 'out and about' and Coca-Cola - When 'at home' variables. Note, the order you select these variables determines where they are placed in the calculation.
2. From the toolbar, click Calculation and select Divide, Multiply or Subtract.
3. A new variable will be created directly after the selected variable set(s) which applies the specified formula on the selected variable(s).
4. OPTIONAL: When you select the new variable, in the object inspector it will display the variables that have been used. You can change the variables by using the relevant drop-down.
5. OPTIONAL: If you only select a single variable, it will default to a Single numeric value of 1 for the second reference. You can change this value as required to update your calculation.
6. OPTIONAL: You can additionally switch either reference between a Variable and a Single numeric value if required.
Note, if you perform this on nominal variables, the calculation will use the underlying values.
Method - Average, Sum, Maximum, Minimum, Any of, None of, Count, Standard Deviation, Variance
1. Select the variables in Data Sources that you wish to use in your calculation. For example, let's select all the Coca-Cola variables from the When 'out and about' group. Note, the order you select these variables determines where they are placed in the calculation.
2. From the toolbar, click Calculation and select Average, Sum, Maximum, Minimum, Any of, None of, Count, Standard Deviation or Variance in both sub-menus, e.g. Average > Average.
3. A new variable will be created directly after the selected variable set(s) which applies the specified formula on the selected variable(s).
4. OPTIONAL: When you select the new variable, in the object inspector it will display the variables that have been used. You can change, remove or add to the variables drop-down as required:
5. OPTIONAL: In Calculate for observations with incomplete data if set to 'Yes', any missing values are removed from the data before the calculation occurs. Ig set to 'No', cases with any missing values will be assigned a missing value. Cases whose values are entirely missing, will always be assigned a missing value regardless of this setting.
6. OPTIONAL: For the Any of, None of and Count options where you are working with numeric data, you can additionally adjust Values to count. This takes the format of individual specified values or a range of values, e.g. 0-10 or 1,2,3 or >1. When working with categorical data, you instead specify the Categorical labels to include.
Next
How to Create a Custom R Text Variable
How to Create a Custom Numeric R Variable
How to Perform Mathematical Calculations on Tables
How to Perform Mathematical Calculations Using R
Bespoke Analyses and Calculations