[R] rtriang using ifelse statement

Diann Prosser dprosser at usgs.gov
Sat Mar 17 20:22:07 CET 2012


Thank you for that explanation and solution David.

As a follow-up to ifelse working on vectors, earlier I tried to coerce
(?correct term?) the matrix into a vector but I still received the same
result.  Should the following work, or does as.vector not work that way,
even though vect now prints as a vector?

> library(mc2d)
> matrx <- matrix(c(2, 1, 1, 2, 2,1), nc=3)
> vect <- as.vector(matrx)
> *vect*
[1] *2 1 1 2 2 1*
> # rtriang from mc2d package: function (n, min = -1, mode = 0, max = 1) 
> dvect<- ifelse(vect==1, rtriang(4, min=0.001, mode=as.vector(vect),
> max=2.001), rtriang(4, min=2, mode=as.vector(vect), max=3))
Warning message:
In rtriang(4, min = 2, mode = as.vector(vect), max = 3) : NaN in rtriang
>* dvect*
[1] *2.3838913 0.5752171 0.3598679 2.0560875 2.3838913 0.5752171*


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



More information about the R-help mailing list