[R] why outer function is failing?
Jeff Newmiller
jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Mon May 4 21:32:16 CEST 2020
The outer function only calls FUN once with two vectors representing all combinations of the inputs. If rolldie is not vectorized then it will have trouble with this input.
Why aren't you using sample?
On May 4, 2020 11:51:03 AM PDT, Yousri Fanous <yousri.fanous using gmail.com> wrote:
>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]]
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
--
Sent from my phone. Please excuse my brevity.
More information about the R-help
mailing list