Skip to content
Course Notes: Introduction to R
add text here chapter DataFrames: the function head() enables you to show the first observations of a data frame. Similarly, the function tail() prints out the last observations in your dataset.
Both head() and tail() print a top line called the 'header', which contains the names of the different variables in your dataset.
# Write and run code here
# Build factor_survey_vector with clean levels
survey_vector <- c("M", "F", "F", "M", "M")
factor_survey_vector <- factor(survey_vector)
levels(factor_survey_vector) <- c("Female", "Male")
# Male
male <- factor_survey_vector[1]
# Female
female <- factor_survey_vector[2]
# Battle of the sexes: Male 'larger' than female?
male > female #How interesting! By default, R returns NA when you try to compare values in a factor, since the idea doesn't make sense. Next you'll learn about ordered factors, where more meaningful comparisons are possible. error= male > female
Warning message: ‘>’ not meaningful for factors
[1] NA