possibly() का एक और तरीका purrr करने का

purrr के साथ Functional Programming की बुनियाद

Auriel Fournier

Instructor

a <- list(-10, "unknown", 10) %>%
  map(safely(function(x) 
  x * 10, 
  otherwise = NA_real_))
a
[[1]]
[[1]]$result
[1] -100
[[1]]$error
NULL

[[2]]
[[2]]$result
[1] NA
[[2]]$error
<simpleError in x * 10: non-numeric 
argument to binary operator>

[[3]]
[[3]]$result
[1] 100
[[3]]$error
NULL
purrr के साथ Functional Programming की बुनियाद

possibly()

a <- list(-10, "unknown", 10) %>%
     map(possibly(function(x) 
         x * 10, 
         otherwise = NA_real_))
a
[[1]]
[1] -100

[[2]]
[1] NA

[[3]]
[1] 100
purrr के साथ Functional Programming की बुनियाद

चलो purrr-actice करें!

purrr के साथ Functional Programming की बुनियाद

Preparing Video For Download...