SDS 192: Introduction to Data Science
Lindsay Poirier Statistical & Data Sciences, Smith College
Fall 2022
pit %>% filter(State == "AK" & Year == 2015) |> summarize(Total = sum(Count))
pit %>% filter(State == "AL" & Year == 2015) |> summarize(Total = sum(Count))
pit %>% filter(State == "AR" & Year == 2015) |> summarize(Total = sum(Count))
function_name <- function(arg1, arg2) { x <- #Some code goes here referencing arg1 and arg2 return(x) }
calculate_difference <- function(arg1, arg2) { x <- arg1 - arg2 return(x) }
R
function_name(value_for_arg1, value_for_arg2)
calculate_difference(7, 3)
[1] 4
state_name
calculate_state_total <- function(state_name) { x <- pit %>% filter(State == state_name & Year == 2015) |> summarize(Total = sum(Count)) return(x) }
calculate_state_total("AL")
calculate_state_total <- function(state_name, year = 2020) { x <- pit %>% filter(State == state_name & Year == year) |> summarize(Total = sum(Count)) return(x) }
calculate_state_total("AL", 2019)
calculate_state_total(state_name = "AL", year = 2019)