[R] rtriang using ifelse statement

Diann Prosser dprosser at usgs.gov
Sat Mar 17 19:36:07 CET 2012


Hi All,

I want to draw samples (n=4)  from one of 2 triangular distributions for
each value in a matrix. I am using an ifelse statement to try to define
which distribution to draw from. 

>From the output, I can see that the ifelse statement is choosing the correct
distribution, however, my n=4 simulations aren't occurring. Is there a way
to adjust the ifelse statement to fix this, or must I take an entirely
different approach? Many thanks for your help.

> matrx <- matrix(c(2, 1, 1, 2, 2,1), nc=nx)
> matrx
     [,1] [,2] [,3]
[1,]    2    1    2
[2,]    1    2    1
> # rtriang from mc2d package: function (n, min = -1, mode = 0, max = 1) 
>* dmatrx<- ifelse(matrx==1, rtriang(4, min=0.001, mode=matrx, max=2.001),
rtriang(4, min=2, mode=matrx, max=3))*
Warning message:
In rtriang(4, min = 2, mode = matrx, max = 3) : NaN in rtriang
> dmatrx
          [,1]     [,2]      [,3]
[1,] 2.7627761 1.305099 2.7627761
[2,] 0.6158242 2.218274 0.6158242
#(this output should have 4 times as many elements)


--
View this message in context: http://r.789695.n4.nabble.com/rtriang-using-ifelse-statement-tp4481037p4481037.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list