mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-22 12:32:09 +03:00
Remove binary gender example from R (#4082)
This commit is contained in:
parent
ab85932812
commit
c351cab657
@ -255,16 +255,16 @@ c('Z', 'o', 'r', 'r', 'o') == "Z" # TRUE FALSE FALSE FALSE FALSE
|
||||
|
||||
# FACTORS
|
||||
# The factor class is for categorical data
|
||||
# Factors can be ordered (like childrens' grade levels) or unordered (like gender)
|
||||
factor(c("female", "female", "male", NA, "female"))
|
||||
# female female male <NA> female
|
||||
# Levels: female male
|
||||
# Factors can be ordered (like childrens' grade levels) or unordered (like colors)
|
||||
factor(c("blue", "blue", "green", NA, "blue"))
|
||||
# blue blue green <NA> blue
|
||||
# Levels: blue green
|
||||
# The "levels" are the values the categorical data can take
|
||||
# Note that missing data does not enter the levels
|
||||
levels(factor(c("male", "male", "female", NA, "female"))) # "female" "male"
|
||||
levels(factor(c("green", "green", "blue", NA, "blue"))) # "blue" "green"
|
||||
# If a factor vector has length 1, its levels will have length 1, too
|
||||
length(factor("male")) # 1
|
||||
length(levels(factor("male"))) # 1
|
||||
length(factor("green")) # 1
|
||||
length(levels(factor("green"))) # 1
|
||||
# Factors are commonly seen in data frames, a data structure we will cover later
|
||||
data(infert) # "Infertility after Spontaneous and Induced Abortion"
|
||||
levels(infert$education) # "0-5yrs" "6-11yrs" "12+ yrs"
|
||||
|
Loading…
Reference in New Issue
Block a user