Get startedGet started for free

Battle of the sexes

You might wonder what happens when you try to compare elements of a factor. In factor_survey_vector you have a factor with two levels: "Male" and "Female". But how does R value these relative to each other?

This exercise is part of the course

Introduction to R

View Course

Exercise instructions

Read the code in the editor and submit the answer to test if male is greater than (>) female.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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
Edit and Run Code