Problemas ainda mais complexos

Fundamentos de Programação Funcional com purrr

Auriel Fournier

Instructor

E se os valores desejados estiverem ocultos?

library(repurrrsive)
data(gh_repos)

forks <- gh_repos %>% 
  map( ~map(.x, "forks"))

forks
[[1]]
[[1]][[1]]
[1] 0

[[1]][[2]]
[1] 1

[[1]][[3]]
[1] 0

[[1]][[4]]
[1] 0
Fundamentos de Programação Funcional com purrr

Estatísticas-resumo com purrr

# Create an empty data frame
bird_df <- data.frame(weight=NA, 
        wing_length=rep(NA, 4))

# Extract the bird names
bird_df$taxa <- 
        names(bird_measurements)

# For loop to pull out each species 
for(i in 1:4){
bird_df[i,] <- 
        bird_measurements[[i]]  
    }
summary(bird_df)
Fundamentos de Programação Funcional com purrr

Estatísticas-resumo

bird_measurements %>% 
  map_df(~ data_frame(
  weight = .x[["weight"]],
  wing_length = .x[["wing length"]],
  taxa = "bird")) %>%
     select_if(is.numeric)  %>%
     summary(.x)

$weight
  Min. 1st Qu.  Median    
  7.00   59.12   86.45 

  Mean 3rd Qu.    Max.
  69.97   97.30  100.00 

$wing_length
  Min. 1st Qu.  Median    
  12.00   29.25   55.00   

  Mean 3rd Qu.    Max. 
  63.00   88.75  130.00
Fundamentos de Programação Funcional com purrr

Vamos praticar!

Fundamentos de Programação Funcional com purrr

Preparing Video For Download...