[R] A problem about outer()

Thomas Lumley tlumley at u.washington.edu
Mon Feb 28 17:00:48 CET 2005


On Mon, 28 Feb 2005, Feng Chen wrote:

> Dear all,
>
> I have something about function outer() that I can't understand. Just 
> see the following example. The two NaNs are due to 0/0, but I can't 
> figure out the cause of the last two errors. I wonder if some one can 
> explain this for me.

Look at FAQ 7.18.

 	-thomas

> ___________________________________________________________________
>> sx=rbinom(10,1,0.5);ot=rbinom(10,1,0.5);ag <- rbinom(10,100,0.3);ho <- rbinom(10,100,0.5)
>> dp <- function(s,a,h)sum((sx==s)&(ag==a)&(ho==h)&(ot==1))/sum((sx==s)&(ag==a)&(ho==h))
>> (function(x,y)dp(1,x,y))(2,3)
> [1] NaN
>> (function(x,y)dp(0,x,y))(27,52)
> [1] NaN
>> dpm <- outer(ag,ho,function(x,y)dp(1,x,y))
> Error in outer(ag, ho, function(x, y) dp(1, x, y)) :
> dim<- : dims [product 100] do not match the length of object [1]
>> dpf <- outer(ag,ho,function(x,y)dp(0,x,y))
> Error in outer(ag, ho, function(x, y) dp(0, x, y)) :
> dim<- : dims [product 100] do not match the length of object [1]
>>
> -------------------------------------------------------------------------------------------------------------------
>
> Thanks very much,
> Feng
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list