Determine the number of occurrences of a word in an R array

How would I use R to determine the number of times the word "RED" occurs in the following array:

test <- c("RED","WHITE","RED","RED")

Upvotes: 0

Views: 40

Answers (1)

SabDeM
SabDeM

Reputation: 7190

Here is my answer:

sum(test == "RED")
[1] 3

Upvotes: 1

Related Questions