Assuming you have a data frame in R, you can first create a logical vector indicating whether the specific word exists in a certain column using grepl()
. Then, you can use this logical vector to subset the data frame using subsetting with square brackets [ ]
. Here's an example:
main.r329 chars9 lines
This will output:
main.r50 chars3 lines
In this example, the grepl("Engineer", df$Occupation)
function creates a logical vector that is TRUE for rows where "Engineer" appears in the Occupation column. The [ ]
operator subsets the rows of the data frame using this vector.
gistlibby LogSnag