매우 간단한 질문이지만 해결책을 찾기 위해 고심 중입니다.변수 대체 - R
이로 가고 싶어 : 여기에
a = c("the sky is color", "the color dog", "grass is color")
b = c("blue","brown","green")
df = data.frame(a,b)
:
a = c("the sky is color", "the color dog", "grass is color")
b = c("blue","brown","green")
c = c("the sky is blue", "the brown dog", "grass is green")
df = data.frame(a,b,c)
는 GSUB 사용하여 시도 :
df$d <- gsub('color', df$b, df$a)
을하지만,이 오류 메시지 수신 :
argument 'replacement' has length > 1 and only the first element will be used
,691을
솔루션은 정수에도 사용할 수 있습니까? 고맙습니다!
본 적이 있습니까? http://stackoverflow.com/questions/19424709/r-gsub-pattern-vector-and-replacement-vector – joemienko