ปัญหาที่ซับซ้อนยิ่งขึ้น

Foundations of Functional Programming with purrr

Auriel Fournier

Instructor

ถ้าค่าที่ต้องการซ่อนอยู่ลึกๆ ล่ะ?

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
Foundations of Functional Programming with purrr

สถิติสรุปด้วย 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)
Foundations of Functional Programming with purrr

สถิติสรุป

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
Foundations of Functional Programming with purrr

มาฝึกกันเถอะ!

Foundations of Functional Programming with purrr

Preparing Video For Download...