[R] lapply and runif issue?
Bert Gunter
bgunter.4567 at gmail.com
Wed Nov 15 02:11:39 CET 2017
Could someone please explain the following? I did check bug reports, but
did not recognize the issue there. I am reluctant to call it a bug, as it
is much more likely my misunderstanding. Ergo my request for clarification:
## As expected:
> lapply(1:3, rnorm, n = 3)
[[1]]
[1] 2.481575 1.998182 1.312786
[[2]]
[1] 2.858383 1.827863 1.699015
[[3]]
[1] 1.821910 2.530091 3.995677
## Unexpected by me:
> lapply(1:3, runif, n = 3)
[[1]]
[1] 1 1 1
[[2]]
[1] NaN NaN NaN
[[3]]
[1] NaN NaN NaN
Warning messages:
1: In FUN(X[[i]], ...) : NAs produced
2: In FUN(X[[i]], ...) : NAs produced
## But note, as expected:
> lapply(1:3, function(x)runif(3))
[[1]]
[1] 0.2950459 0.8490556 0.4303680
[[2]]
[1] 0.5961144 0.5330914 0.2363679
[[3]]
[1] 0.8079495 0.1431838 0.3671915
Many thanks for any clarification.
-- Bert
[[alternative HTML version deleted]]
More information about the R-help
mailing list