2016-07-25 2 views
-2

all.ethnicity이라는 벡터가 있습니다. 나는 grepl (또는 모든 기능) "아시아"를 원하고 첫 번째 요소에만 적용되고 두 번째 요소 "남아시아"에 대해서는 사실이 아닙니다. 참고 : ethnicity.type 개체를 사용해야합니다.grepl 전체 문자열 일치 개체를 사용하여

all.ethnicity <- c("Asian", "South Asian", "European") 
ethnicity.type <- "Asian" 
grepl(ethnicity.type,all.ethnicity) 

결과

[1] TRUE FALSE FALSE 
+2

은 아마 단지 all.ethnicity == ethnicity.type''할 수있는 더 의미 ^ 붙여 넣기로 시도 할 수 있습니다 – thelatemail

답변

1

에 한번 당신의 패턴, 예를 들어,에 시작 (^)과 끝 ($) 그룹을 추가

all.ethnicity <- c("Asian", "South Asian", "European") 
ethnicity.type <- "^Asian$" 
grepl(ethnicity.type, all.ethnicity) 
[1] TRUE FALSE FALSE 
1

우리는 (문자열의 즉 시작)

grepl("^Asian", all.ethnicity) 
관련 문제