If you have a categorical data. And you want to do some analysis on it, you will be required to convert the categories into integers. Factor function is used to achieve this objective.
The syntax of factor function is as follows -
factor(data, order=T/F, levels=c(....))
where,
data can be any vector/column of a table which is having categorical data
If the data set is ordinal, then order needs to be set as True. By default it is False. This will allot integers to categories in ascending alphabetical order such that 1 will be considered better than 2 and so on.
The recoding of categories to integers is done in an alphabetical order. That is D gets preference over F. To change this you need to explicitly mention the order in levels argument
if level =c(D,BA) then D=1, B=2, A=3 else by default A =1.B=2,D=3
The syntax of factor function is as follows -
factor(data, order=T/F, levels=c(....))
where,
data can be any vector/column of a table which is having categorical data
If the data set is ordinal, then order needs to be set as True. By default it is False. This will allot integers to categories in ascending alphabetical order such that 1 will be considered better than 2 and so on.
The recoding of categories to integers is done in an alphabetical order. That is D gets preference over F. To change this you need to explicitly mention the order in levels argument
if level =c(D,BA) then D=1, B=2, A=3 else by default A =1.B=2,D=3
No comments:
Post a Comment