# Use this R-Chunk to import all your datasets!
let <- readr::read_lines("https://byuistats.github.io/M335/data/randomletters.txt")
letnum <- readr::read_lines("https://byuistats.github.io/M335/data/randomletters_wnumbers.txt")
This week we will learn new coding techniques and visualization principles. Go back to task 11 and build your code into two or three functions that performs the same work for the tasks.
Functions
Repeat the task 11 tasks using three functions that you built
letter1700 <- let %>%
str_split("") %>%
unlist() %>%
.[c(1, seq(0, str_count(let), 1700))] %>%
str_flatten() %>%
str_remove_all('\\..*$')
letter1700
## [1] "the plural of anecdote is not data"
numlet <- letnum %>%
str_extract_all('[:digit:]+') %>%
unlist() %>%
as.integer() %>%
letters[.] %>%
paste(collapse = '')
numlet
## [1] "expertsoftenpossessmoredatathanjudgment"
spacelet <- let %>%
str_remove_all('\\.') %>%
str_remove_all('[:space:]') %>%
str_locate('[aeiou]')
spacelet
## start end
## [1,] 7 7
pullout <- function(df, n){
df %>%
str_split("") %>%
unlist() %>%
.[c(1, seq(0, str_count(df), n))] %>%
str_flatten() %>%
str_remove_all('\\..*$')
}
numberconvert <- function(df){
df %>%
str_extract_all('[:digit:]+') %>%
unlist() %>%
as.integer() %>%
letters[.] %>%
paste(collapse = '')
}
spacevowels <- function(df){
df %>%
str_remove_all('\\.') %>%
str_remove_all('[:space:]') %>%
str_locate('[aeiou]')
}
pullout(let, 1700)
## [1] "the plural of anecdote is not data"
numberconvert(letnum)
## [1] "expertsoftenpossessmoredatathanjudgment"
spacevowels(let)
## start end
## [1,] 7 7