Factors in R are like vectors, but with one more attribute. If you turn some vector into factor, it's going to preserve elements, but it's going to get additional collection of elements in it, called levels. Levels are basically unique element from that vector. A top of all of that, we could provide optional parameter to function factor, called levels that accepts vector as value and in that vector, we are going to arrange levels in order we prefer.
a <- c("m", "m", "f", "m")
b <- factor(a, levels= c("m", "f"))
Video tutorial link below:
No comments:
Post a Comment