🐌 I want to … create three normal distribution with purrr::map as simple as possible
🐌 Here’s how to: library(tidyverse) #rnorm(n=5, mean = mu, sd = sigma) #函数的一般形式 black_box <- partial(rnorm, n=5)# 先把不变的固定下来,生成新的黑箱函数,黑箱函数只需要接受 map 传递的参数即可, 其他的参数已经通过 ·partial· 固定下来了 mu <- list(10, 100, -100)# 参数 x sigma <- list(0.01, 1, 10)# 参数 y map2(mu, sigma, ~ black_box(mean=.x, sd=.y)) %>% do.call(cbind, .) ## [,1] [,2] [,3] ## [1,] 10.
What is an adverb Read carefully the purrr documentation
Adverbs modify the action of a function ; taking a function as input and returning a function with modified action as output.
In other words, adverbs take a function, and return this function modified. Yes, just an adverb modifies a verb.
library(purrr) safe_log <- safely(log)#high-order functions safe_log("a") ## $result ## NULL ## ## $error ## <simpleError in log(x = x, base = base): non-numeric argument to mathematical function> # have a result and error how to write your own?