How to delete variables from your dataset with R
When starting to work on your dataset you may like to permanently delete (remove) variables because you know they are you not going to need them at all. The alternative is that you can hide variables so that they still exist in your dataset (you just can't see them in the web app).
The template code to use
ds %>% deleteVariables(variables)
What you need:
- Your dataset loaded and stored as a
- A list of variables (in a table or Excel or CSV)
Replace the variables part above with the list of variable aliases that you want to delete. These need to be in the concatenate function so it looks like this:
ds %>% deleteVariables(c("var"1, "var2", "var3", var4")
Typing out a long list of variables can be a bore - so there's a shortcut below that can do this for you.
- Go to this website: https://convert.town/column-to-comma-separated-list
- Adjust the settings with the cog on the right-hand side (above the green box) to match the settings in the picture below (with the delimiters, item prefix, etc)
- Copy that into your R code (replacing the red text above)
Worked example
Suppose you had a dataset and you had a list (in Excel) of variables you wanted to delete
- Dataset: Cola Tracking - January to September.sav
- List of variables in Excel: variable list to delete.xlsx
- Upload this dataset
- Go through the instructions above
- Your code should look like the below
- Run that code in your R app (R Studio)
- Refresh your web browser to check it worked
Your code should look like the below:
ds %>% deleteVariables(c("q9_0_1","q9_0_2","q9_0_3","q9_0_4","q9_0_5","q9_0_6","q9_0_7","q9_0_8","q9_1_1","q9_1_2","q9_1_3","q9_1_4","q9_1_5","q9_1_6","q9_1_7","q9_1_8","q9_2_1","q9_2_2","q9_2_3","q9_2_4","q9_2_5","q9_2_6","q9_2_7","q9_2_8"))