user28575 - 4 years ago 100

R Question

This is a problem in R for data science by Hadley.

The results for map(-2:2, rnorm, n = 5) is a list of 5 double vector.

and map_dbl(-2:2, rnorm, n = 5) is a error says "Error: Result 1 is not a length 1 atomic vector".

But I don't know why.

Thanks.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

`map(-2:2, rnorm, n = 5)`

is the list of vectors `rnorm(-2, n=5)`

, `rnorm(-1, n=5)`

, `rnorm(0, n=5)`

, `rnorm(1, n=5)`

, `rnorm(2, n=5)`

.

Since these vectors have not length 1, `map_dbl(-2:2, rnorm, n = 5)`

throws an error. For example `map_dbl(-2:2, rnorm, n = 1)`

does not return an error, it is the vector made of `rnorm(-2, n=1)`

, `rnorm(-1, n=1)`

, `rnorm(0, n=1)`

, `rnorm(1, n=1)`

, `rnorm(2, n=1)`

.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**