Factors

2020

Libraries

library(tidyverse)
library(skimr)

Data

A dataset1 source, documentation from 1999, collected by Amy R. Moore, a student at Grinnell College in Iowa.

Recoding

The color variable in the dataset is described as “Egg color (0 = plain/solid or 1 = speckled/spotted)”. Moreover, read_csv reads the variable in as a numerical value

birds <- read_csv("BirdNest.csv")
birds %>%
    select(Color) %>%
    summary()
#>      Color       
#>  Min.   :0.0000  
#>  1st Qu.:1.0000  
#>  Median :1.0000  
#>  Mean   :0.8333  
#>  3rd Qu.:1.0000  
#>  Max.   :1.0000

mutate2 Create or transform variables, factor3 Factors, and fct_recode4 Change factor levels by hand can resolve both issues.

birds %>%
    mutate(
        Color = factor(Color),
        Color = fct_recode(Color,
            "Plain / Solid" = "0",
            "Speckled / Spotted" = "1"
        )
    ) %>%
    select(Color) %>%
    summary()
#>                 Color   
#>  Plain / Solid     :14  
#>  Speckled / Spotted:70