Collapsing levels
If it was difficult to work with the heavy skew of exclaim_mess, the number of images attached to each email (image) poses even more of a challenge. Run the following code at the console to get a sense of its distribution:
table(email$image)
Recall that this tabulates the number of cases in each category (so there were 3811 emails with 0 images, for example). Given the very low counts at the higher number of images, let's collapse image into a categorical variable that indicates whether or not the email had at least one image. In this exercise, you'll create this new variable and explore its association with spam.
Este ejercicio forma parte del curso
Análisis exploratorio de datos en R
Instrucciones del ejercicio
Starting with email, form a continuous chain that links together the following tasks:
- Create a new variable called
has_imagethat isTRUEwhere the number of images is greater than zero andFALSEotherwise. - Create an appropriate plot with
emailto visualize the relationship betweenhas_imageandspam.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Create plot of proportion of spam by image
email %>%
mutate(has_image = ___) %>%
ggplot(aes(x = ___, fill = ___)) +
geom_bar(position = ___)