# It is used to store the distinct data it make the code run faster if you are having large amount of data
# because it just store the distinct values with index numbers.
labels = c('Asia','Africa','Oceania','Europe','Antarctica','North America'
,'South America','Africa','Europe')
factor_labels = factor(labels)
factor_labels
# to get the length of the factor
length(factor_labels)
# to get the levels of a factor(how many distinct values are there)
nlevels(factor_labels)
class(factor_labels)
typeof(factor_labels)
# changing the factor into numeric
as.numeric(factor_labels)
as.integer(factor_labels)
Altitude_levels = c('High','Low','Medium','High','Low')
altitude_f = factor(Altitude_levels)
# you can access factor same as vector with index number not with element name
altitude_f[5]
#making order in factor
altitude_factor = factor(Altitude_levels, order=TRUE, levels=c('Low','Medium','High'))
as.integer(altitude_factor)
To embed this project on your website, copy the following code and paste it into your website's HTML: