Test if Vector Contains Certain Element in R (Example) | Check for Given Value with %in% Operator

preview_player
Показать описание

R Code of the tutorial:

vec <- c("AAA", "Hello", "12345", "X") # Create example vector

"AAA" %in% vec # Test if AAA is in vector
# TRUE

"A" %in% vec # Test if A is in vector
# FALSE
Рекомендации по теме
Комментарии
Автор

Nice vid, however, what should i do if i wanna see if the dataset contains specific words like:

vec <- c("Yorklea Croft", "Yorke Avenue", "Woodthorpe Drive")
Want to find value that contains "Yorke"

Just like %Yorke% in SQL

Is that possible to do that with %in%? Thank you so much!

jamesyip
Автор

nice video I have one question I am using iris dataset and I want to sum up all the Virinica from species for this I use this code " sum("virinica" %in% iris$species)" and it shows only #1

shaheryarshafi