[R] Three values that add to the same number by 0.01 steps
S Ellison
S.Ellison at lgcgroup.com
Tue Jan 28 18:36:49 CET 2014
> 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 away the oversized ones
m <- cbind(m, x3=100-rowSums(m)) #Get the final column
m <- m/100 #Scale to [0,1]
table(rowSums(m))
S Ellison
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
More information about the R-help
mailing list