library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
setwd("/Users/smhenderson/Desktop/DATA101/Project")
lowbirthweight <- read.csv("Low birth-weight babies by race and ethnicity.csv")
names(lowbirthweight) <- tolower(names(lowbirthweight)) #create lowercase
names(lowbirthweight) <- gsub(" ","",names(lowbirthweight)) #removes unwanted spaces
#removes unwanted values in the location, dataformat, and racegroup variables
lowbirthweight2 <- lowbirthweight %>%
filter(location != "United States") %>%
filter(dataformat != "Percent") %>%
filter(race.group != "Total") %>%
mutate(race.group = recode(race.group, "Asian and Pacific Islander" = "American/Pacific Islander", "Black or African American" = "Black", "Hispanic or Latino" = "Latinx","Non-Hispanic White" = "White", "Two or more races" = "Multiracial")) #rename the different groups
lowbirthweight2$data <- as.numeric(lowbirthweight2$data) #convert data variable to easily sum
## Warning: NAs introduced by coercion
lowbirthweight3 <- lowbirthweight2 %>%
filter(!is.na(data)) #removes blanks