user5514390
user5514390

Reputation:

Getting rows of data with multiple columns condition in R

I have a set of dataset, but I would like to extract rows that contain specific keywords.

I tried using the codes below, and it works. But I just wondering if there is any better way in doing this.

test1 <- subset(data, grepl("love|hate", Content))
test2 <- subset(data, grepl("love|hate", Articles))
together <- unique(rbind(test1, test2))

I tried combining together, but failed to do so:

test1 <- subset(data, grepl("love|hate", Content, Articles))

Upvotes: 1

Views: 45

Answers (1)

Carl
Carl

Reputation: 5779

Try this:

data[grepl("love|hate",data$Content) & grepl("love|hate",data$Articles),]

Upvotes: 1

Related Questions