Re: [R] Three values that add to the same number by 0.01 steps

2014-01-28 Thread arun
Also, library(gtools)  x <- rdirichlet(1000, c(1,1,1) ) any(!rowSums(x)) #[1] FALSE A.K. On Tuesday, January 28, 2014 2:20 PM, Richard Kwock wrote: An alternative using runif. x <- round(runif(1, 0, 1), 2) y <- round(runif(1, 0, 1-x), 2) z <- round(1-x-y, 2) sum1 <- cbind(x, y, z)

Re: [R] Three values that add to the same number by 0.01 steps

2014-01-28 Thread Richard Kwock
An alternative using runif. x <- round(runif(1, 0, 1), 2) y <- round(runif(1, 0, 1-x), 2) z <- round(1-x-y, 2) sum1 <- cbind(x, y, z) any(!(sum1[,1] + sum1[,2] + sum1[,3])) Richard On Tue, Jan 28, 2014 at 9:36 AM, S Ellison wrote: > > I'd like to create a matrix with three columns

Re: [R] Three values that add to the same number by 0.01 steps

2014-01-28 Thread S Ellison
> I'd like to create a matrix with three columns so that each element is > between 0 and 1 and each row always adds to 1. So, if in the same row the You could start with expand.grid m <- expand.grid(x1=0:100, x2=0:100) #Avoids comparing floats m <- m[rowSums(m)<=100,]#Throw a

Re: [R] Three values that add to the same number by 0.01 steps

2014-01-28 Thread arun
Hi, May be this helps:  set.seed(85)  mat1 <- matrix(sample(seq(0,1,by=0.01),36,replace=TRUE),ncol=3) mat2 <- mat1[sprintf("%.2f",rowSums(mat1))=="1.00",]  any(!rowSums(mat2)) #[1] FALSE A.K. Hi, I'd like to create a matrix with three columns so that each element is between 0 and 1 and eac