Tutorial by Examples

Factors are one way to represent categorical variables in R. A factor is stored internally as a vector of integers. The unique elements of the supplied character vector are known as the levels of the factor. By default, if the levels are not supplied by the user, then R will generate the set of uniq...
There are times in which it is desirable to consolidate factor levels into fewer groups, perhaps because of sparse data in one of the categories. It may also occur when you have varying spellings or capitalization of the category names. Consider as an example the factor set.seed(1) colorful <...
Factors are one method to represent categorical variables in R. Given a vector x whose values can be converted to characters using as.character(), the default arguments for factor() and as.factor() assign an integer to each distinct element of the vector as well as a level attribute and a label attr...
When factors are created with defaults, levels are formed by as.character applied to the inputs and are ordered alphabetically. charvar <- rep(c("W", "n", "c"), times=c(17,20,14)) f <- factor(charvar) levels(f) # [1] "c" "n" "W" ...
Problem Factors are used to represent variables that take values from a set of categories, known as Levels in R. For example, some experiment could be characterized by the energy level of a battery, with four levels: empty, low, normal, and full. Then, for 5 different sampling sites, those levels c...

Page 1 of 1