내가 바로 질문을 가지고 있지만, 당신은 당신이 "알파"경우 테스트 할 말은 경우 열 문자에 있는지 확실하지 않습니다 -Test이면 다음과 같이 작동합니다.
> df <- data.frame("Letter-Test" = c("Alpha - Test", "Beta- Test", "Zeta-Test", "Alpha-Two", "Beta-Two"),
+ stringsAsFactors = FALSE)
>
> ifelse(test = grepl("Alpha", df$Letter.Test), yes = "Alpha", no = df$Letter.Test)
[1] "Alpha" "Beta- Test" "Zeta-Test" "Alpha" "Beta-Two"
테스트가 TRUE 일 경우 거짓 d. 편지. 편지.
아니면 데이터 프레임의 새로운 열에 직접 결과를 넣을 수 있습니다 :
> df$AplhaTest <- ifelse(test = grepl("Alpha", df$Letter.Test), yes = "Alpha", no = df$Letter.Test)
> df
Letter.Test AplhaTest
1 Alpha - Test Alpha
2 Beta- Test Beta- Test
3 Zeta-Test Zeta-Test
4 Alpha-Two Alpha
5 Beta-Two Beta-Two
것은'참조 dplyr :: case_when' : https://www.rdocumentation.org/packages/dplyr/versions/0.7.3/topics/case_when 당신은'sqldf' 라이브러리를 사용하고 실제 사용할 수 있습니다 – www
SQL 명령. 그렇지 않으면, 나는 정규식을 좋아한다. 'grepl ("Alpha", df $ Letter_Test, fixed = TRUE)'는 논리 벡터를 반환하므로'ifelse()'를 쉽게 래핑하여 값을 할당 할 수 있습니다. – Mako212