factorial in r code example
Example 1: what is factor in r programming
data <- c("East","West","East","North","North","East","West","West","West","East","North")
print(data)
print(is.factor(data))
factor_data <- factor(data)
print(factor_data)
print(is.factor(factor_data))
Example 2: factor in r
f <- levels(f)[f]
f <- as.numeric(f)
Example 3: How to Convert a Factor in R
> directions <- c("North", "East", "South", "South")
> directions.factor <- factor(directions)
> directions.factor
[1] North East South South
Levels: East North South