Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A little Problem in section 5.5.2 Factors #38

Open
alibalapour opened this issue Aug 23, 2020 · 0 comments
Open

A little Problem in section 5.5.2 Factors #38

alibalapour opened this issue Aug 23, 2020 · 0 comments

Comments

@alibalapour
Copy link

5.5.2 Factors :
"R uses the levels attribute when it displays the factor, as you will see. R will display each 1 as female, the first label in the levels vector, and each 2 as male, the second label. If the factor included 3s, they would be displayed as the third label, and so on: …"

It's wrong! Because if we add an object that start with a letter that's alphabetically before 'f' , for example starts with 'a' in 'another' , the labels of factor class will change. It will be :
'another' ---> 1
'female' ---> 2
'male' ---> 3
To be more obvious, I write this part of code:

gender <- factor(c("male", "female", "another", "female", "another", "male"))
unclass(gender)
## [1] 3 2 1 2 1 3
## attr(,"levels")
## [1] "another" "female"  "male"

You saw that the label of "another" is 1. That means the numbering of the factor is alphabetical.

sorry for my bad English. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant