Re: [R] Sum of Probabilities in a matrix...

2011-10-01 Thread Rolf Turner
On 02/10/11 14:06, Jim Silverton wrote: Hi all, I have 2 columns in a mtrix, one of which is a column of probabilities and the other is simply a vector of integers. I want to sum all the probabilities with the same integer value and put it in a new column. For example, If my matrix is: 0.98 2

Re: [R] Sum of Probabilities in a matrix...

2011-10-01 Thread Dennis Murphy
Let's make it a data frame instead: # Read the data from your post into a data frame named d: d <- read.table(textConnection(" 0.98 2 0.2 1 0.01 2 0.5 1 0.6 6")) closeAllConnections() # Use the ave() function and append the result to d: d$sumprob <- with(d, ave(V1, V2, FUN = sum))

Re: [R] Sum of Probabilities in a matrix...

2011-10-01 Thread Jim Silverton
Hi all, I have 2 columns in a mtrix, one of which is a column of probabilities and the other is simply a vector of integers. I want to sum all the probabilities with the same integer value and put it in a new column. For example, If my matrix is: 0.98 2 0.2 1 0.01 2 0.5 1 0.6 6 T