Challenge 9 - Creating a function

Pull in data

prevUseAT <- read_csv("Prev_Use_AT.csv")
## Rows: 1430 Columns: 34
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (15): IndicatorCode, Indicator, ValueType, ParentLocationCode, ParentLo...
## dbl   (3): Period, FactValueNumeric, FactValueTranslationID
## lgl  (15): IsLatestYear, Dim2 type, Dim2, Dim2ValueCode, Dim3 type, Dim3, Di...
## dttm  (1): DateModified
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(prevUseAT)
## # A tibble: 6 × 34
##   IndicatorCode            Indicator ValueType ParentLocationCode ParentLocation
##   <chr>                    <chr>     <chr>     <chr>              <chr>         
## 1 ASSISTIVETECH_USEPREVAL… Prevalen… numeric   EUR                Europe        
## 2 ASSISTIVETECH_USEPREVAL… Prevalen… numeric   EUR                Europe        
## 3 ASSISTIVETECH_USEPREVAL… Prevalen… numeric   EUR                Europe        
## 4 ASSISTIVETECH_USEPREVAL… Prevalen… numeric   EUR                Europe        
## 5 ASSISTIVETECH_USEPREVAL… Prevalen… numeric   EUR                Europe        
## 6 ASSISTIVETECH_USEPREVAL… Prevalen… numeric   EUR                Europe        
## # ℹ 29 more variables: `Location type` <chr>, SpatialDimValueCode <chr>,
## #   Location <chr>, `Period type` <chr>, Period <dbl>, IsLatestYear <lgl>,
## #   `Dim1 type` <chr>, Dim1 <chr>, Dim1ValueCode <chr>, `Dim2 type` <lgl>,
## #   Dim2 <lgl>, Dim2ValueCode <lgl>, `Dim3 type` <lgl>, Dim3 <lgl>,
## #   Dim3ValueCode <lgl>, DataSourceDimValueCode <lgl>, DataSource <lgl>,
## #   FactValueNumericPrefix <lgl>, FactValueNumeric <dbl>, FactValueUoM <lgl>,
## #   FactValueNumericLowPrefix <lgl>, FactValueNumericLow <lgl>, …

Why this function

There are many different assistive technology (AT) types and I only want to look at different subsets. Rather than filtering out a long list of different ATs every time I am modifying my data frame, I will make it a function to apply when needed

Function for only vision AT

#select vision AT
visionAT <- function(data) {
  filteredForVisionAT <- data %>%
    filter(Dim1 %in% c(
      "Braille displays (note takers)",
      "Braille writing equipment/braillers",
      "Deafblind communicators (for seeing/vision)",
      "Magnifiers, digital handheld",
      "Smart phones/tablets/PDA (for seeing/vision)",
      "White canes",
      "Screen readers",
      "Magnifiers, optical",
      "Spectacles; low-vision, short/long distance/filters etc"
    ))
  
  return(filteredForVisionAT)
}

Function for only Deaf/hard of hearing AT

#select hearing AT
hearingAT <- function(data) {
  filteredForHearingAT <- data %>%
    filter(Dim1 %in% c(
        "Alarm signalers with light/sound/vibration",    
        "Audio-players with DAISY capability", 
        "Closed captioning displays", 
        "Communication boards/books/cards", 
        "Communication software", 
        "Deafblind communicators (for hearing)", 
        "Deafblind communicators (for seeing/vision)", 
        "Gesture to voice technology", 
        "Smart phones/tablets/PDA (for hearing)", 
        "Hearing aids (digital) and batteries", 
        "Hearing loops/FM systems"
    ))
  
  return(filteredForHearingAT)
}

Applying the functions

prevUseATEuro <- prevUseAT %>% 
  filter(ParentLocation == 'Europe')

#filtering a data frame to just look at vision AT
prevUseATEuroVision <- visionAT(prevUseATEuro)

#filtering a data frame to just look at vision AT
prevUseATEuroHearing <- hearingAT(prevUseATEuro)

#next steps could include summarising the data specifically for vision and then specifically for hearing, etc. and join them back together to compare them.