Creating box plot on exercise

The error message is telling you the issue: you can’t use only factors to create a box plot. boxplot is looking for a numeric vector. Run code below as an example:

df <- data.frame(
"age" = c(77,74,55,62,60,59,32,91,75,73,43,67,58,18,57),
"party" = c("Independent", "Independent", "Independent", "Democrat", 
          "Independent", "Republican", "Independent", 
          "Independent", "Democrat", "Republican", "Republican", 
          "Democrat", "Democrat", "Independent", "Independent"),
)

df$party <- as.factor(df$party)
df$age <- as.numeric(df$age)

boxplot(df$party) # gives same error
boxplot(df$age) #runs

see ?boxplot for examples on using formulas in the boxplot function, as that may be what you are looking for? For example:

 boxplot(df$age~df$party)

Leave a Comment

error code: 523