mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00: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
|
# FACTORS
|
||||||
# The factor class is for categorical data
|
# The factor class is for categorical data
|
||||||
# Factors can be ordered (like childrens' grade levels) or unordered (like gender)
|
# Factors can be ordered (like childrens' grade levels) or unordered (like colors)
|
||||||
factor(c("female", "female", "male", NA, "female"))
|
factor(c("blue", "blue", "green", NA, "blue"))
|
||||||
# female female male <NA> female
|
# blue blue green <NA> blue
|
||||||
# Levels: female male
|
# Levels: blue green
|
||||||
# The "levels" are the values the categorical data can take
|
# The "levels" are the values the categorical data can take
|
||||||
# Note that missing data does not enter the levels
|
# 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
|
# If a factor vector has length 1, its levels will have length 1, too
|
||||||
length(factor("male")) # 1
|
length(factor("green")) # 1
|
||||||
length(levels(factor("male"))) # 1
|
length(levels(factor("green"))) # 1
|
||||||
# Factors are commonly seen in data frames, a data structure we will cover later
|
# Factors are commonly seen in data frames, a data structure we will cover later
|
||||||
data(infert) # "Infertility after Spontaneous and Induced Abortion"
|
data(infert) # "Infertility after Spontaneous and Induced Abortion"
|
||||||
levels(infert$education) # "0-5yrs" "6-11yrs" "12+ yrs"
|
levels(infert$education) # "0-5yrs" "6-11yrs" "12+ yrs"
|
||||||
|
Loading…
Reference in New Issue
Block a user