factor

Published by onesixx on

 

 

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()

 

 

 

 

Categories: R Tidyverse

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x