Making top boxes: dichotomize your arrays using R
Very commonly with survey data, we want to turn a categorical array into a "top box" (or "top 2 box", etc) question. Or perhaps you've set up a Yes/No question as a Categorical Array, and you're really only interested in the "Yes" response (that is the same thing in essence as a "top box").
In data processing, this is known as dichotomizing the array, because you're collapsing the data into a binary Yes/No, or 1/0, situation, and thus producing a multiple response variable.
The code works as follows:
- Open this R script (in R Studio): MR Builder v1.R
- Login and load up your dataset
- The code produces a CSV file in your working directory.
- The CSV file shows all the categorical arrays in the dataset. You fill in the CSV and resave.
- Run the rest of the code
How to fill in the CSV
The CSV file will display all the categorical arrays in the dataset.
- You put an "x" in all the boxes that you want to count in the multiple response question.
- You also have the opportunity to rename at this point a multiple response question that's about to be created.
- You don't need to fill in an "x" for every variable displayed, only the ones that you want top boxes for.
Further notes:
- At this time of writing this article, the CSV also displays numeric and text variables - this will be corrected shortly.
- A worked example will be placed here very soon.
- Be sure to overwrite the CSV in your working directory (if using Numbers on a Mac, be sure to "export as a CSV", rather than just save).