-2
我有一个叫all.ethnicity
的载体。我想grepl(或任何函数)“亚洲”,只有第一个元素成为真,而不是第二个元素“南亚”。注意:我必须使用ethnicity.type
对象。grepl使用R中的对象完全匹配字符串
all.ethnicity <- c("Asian", "South Asian", "European")
ethnicity.type <- "Asian"
grepl(ethnicity.type,all.ethnicity)
结果
[1] TRUE FALSE FALSE
可能更有意义只是做'all.ethnicity == ethnicity.type'尝试 – thelatemail