Probleme și mai complexe

Bazele programării funcționale cu purrr

Auriel Fournier

Instructor

Ce facem când valorile sunt îngropate adânc?

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
Bazele programării funcționale cu purrr

Statistici sumare în 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)
Bazele programării funcționale cu purrr

Statistici sumare

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
Bazele programării funcționale cu purrr

Să exersăm!

Bazele programării funcționale cu purrr

Preparing Video For Download...