I'm currently working with a fairly large data set and am looking to subset some of my variables.
I'm essentially trying to select a range of variables then add one single variable in that function, and switch back to selecting a range.
For example:
items_data = subset(dataset, select = q1:19, q20, q33:35, q50)
However I think the commas are causing some issues.
I've been scouring the interwebs for a solution, but have only come across scripts that are more cumbersome, and I know there's an easier solution.
Any help would be greatly appreciated.
Thank you!
You can do the following:
Base R
items_data = dataset[,c(1:20, 33:35, 50)]
Dplyr
#install.packages('dplyr')
library(dplyr)
items_data = select(dataset, 1:20, 33:35, 50)
note that the numbers are column index positions, if your dataset changes, so will the columns it will pull. You can also use the names of the columns instead, to ensure that if your dataset changes, it will retain pulling the same fields.