How to count multiple text values in a column in RStudio

I'm basically new to R, is there a way to count how many times a text value (By text value, I mean a word such as YES or ONE) is present in a specified column in RStudio? I'm thinking about either data.frame or c, however, I'm not quite sure which one is correct. Thank you.

Here's a one way.

df <- data.frame(x = c("YES", "YES", "NO"))

length(which(df$x == "YES"))

You can actually use sum() in place of length(which()) but that's a bit less obvious.

1 Like