[R] why outer function is failing?
Yousri Fanous
you@r|@|@nou@ @end|ng |rom gm@||@com
Mon May 4 20:51:03 CEST 2020
Hello
>From outer help page:
outer takes two vectors
<https://renenyffenegger.ch/notes/development/languages/R/data-structures/vector/index>
and a function (that itself takes two arguments) and builds a matrix
<https://renenyffenegger.ch/notes/development/languages/R/data-structures/matrix/index>
by calling the given function for each combination of the elements in the
two vectors.
x<-1:6
y<-3:10
m<-outer (x,y,function (x,y) rnorm(x,y))
works as expected.
But now when I replace rnorm with rolldie from package (prob) outer
complains
library (prob)
m<-outer (x,y,function (x,y) nrow(rolldie(x,y)))
Error in rep("X", times) : invalid 'times' argument
In addition: Warning messages:
1: In 1:times : numerical expression has 48 elements: only the first used
2: In 1:nsides : numerical expression has 48 elements: only the first used
nrow(rolldie(5,4))
[1] 1024
1) why outer is failing with rolldie?
2) What does the error mean?
As a workaround I can do this thru a double loop, but I was hoping to get a
more efficient way.
Thanks for the help
Yousri Fanous
Software developer
IBM Canada
[[alternative HTML version deleted]]
More information about the R-help
mailing list