factor
cha <- c("A","B","C","D","E") id <- as.factor(c(1,3,5)) cha[id] <- "F" cha [1] "F" "F" "F" "D" "E" cha[as.numeric(as.character(id))] <- "F" cha [1] "F" "B" "F" "D" "F" # factor의값은 level이다. id [1] 1 3 5 Levels: 1 3 5 as.integer(id) [1] 1 2 3 as.character(id) [1] "1" "3" "5" #<참고> levels(cha) <- 1:length(cha) cha [1] "A" "B" "C" "D" "E" attr(,"levels") [1] 1 2 3 4 5 cha()