I’m trying to write code such that I would subset my dataset so that it only includes variables that start with particular letters. For example:
l_raw_2 = l_raw_1[, names(l_raw_1) %in% c(“record_id”, names(l_raw_1)[substr(names(l_raw_1), 1, 2) == “ba”])]
In this code, I am subsetting my data set such that the subsetted dataset only includes variables that start with “BA”. However, is there a way to subset the data set such that it includes variables starting with “BA” and other series of letters (e.g. HX, PE, etc.) all in one string of code? It seems that including an OR statement results in an error. For example:
l_raw_2 = l_raw_1[, names(l_raw_1) %in% c(“record_id”, names(l_raw_1)[substr(names(l_raw_1), 1, 2) == “ba” OR “hx” ])]
Any input regarding this would be much appreciated; thanks so much!