To keep only the columns from a data frame containing the word "blank", you can use the grep()
function to find the columns' names that contain the word "blank", and then subset the original data frame based on that.
Here's an example code snippet:
main.r241 chars6 lines
In this code, we first create an example data frame df
with two columns containing the word "blank" (blank_1
and blank_2
). We then use grep("blank", names(df))
to find the columns containing the word "blank", and subset the data frame using df[, grep("blank", names(df))]
to keep only those columns. The resulting data frame df_blank
will contain only the two columns with "blank" in their name (blank_1
and blank_2
).
gistlibby LogSnag