You can also use rowSums() directly in a dplyr statement.
library(dplyr)
df %>%
mutate(x = rowSums(across(all_of(c("col1", "col2", "col3", "col4", "col5")), `==`, "YES")))
# something col1 col2 col3 col4 col5 x
# 1 0.113703411 NO NO YES NO NO 1
# 2 0.622299405 NO NO NO YES NO 1
# 3 0.609274733 NO NO YES NO NO 1
# 4 0.623379442 YES NO YES NO NO 2
# 5 0.860915384 NO NO YES NO YES 2
# 6 0.640310605 NO NO NO YES NO 1
# 7 0.009495756 NO YES YES YES YES 4
# 8 0.232550506 YES NO NO YES YES 3
# 9 0.666083758 NO NO NO YES NO 1
# 10 0.514251141 NO NO YES NO YES 2
You can also use the tidyselect helpers depending on how your data frame is set up.
df %>%
mutate(x = rowSums(across(starts_with("col"), `==`, "YES")))
df %>%
mutate(x = rowSums(across(col1:col5, `==`, "YES")))
Regarding using na.rm = TRUE. I would not do that. How to handle NA's should require more careful thought. One should not simply assume that an NA is equal to a "NO" without knowing your problem better. If it is a "NO", then I would replace that value at some stage in the workflow instead.
Data:
set.seed(1234)
df <- data.frame(something = runif(10),
col1 = sample(c("YES","NO"),10,replace = T),
col2 = sample(c("YES","NO"),10,replace = T),
col3 = sample(c("YES","NO"),10,replace = T),
col4 = sample(c("YES","NO"),10,replace = T),
col5 = sample(c("YES","NO"),10,replace = T))