Hello,
Better yet is function aggregate.
# Create some data matrix
Y <- matrix(c(sample(80, 507, TRUE), sample(-1:1, 4*507, TRUE)), ncol=5)
X <- aggregate(Y[, 5]~Y[, 1], Y, sum) # In your case Y[, 4] not Y[, 1]
Hope this helps,
Rui Barradas
Em 05-06-2012 09:53, Özgür Asar escreveu:
Hi,
x<
Hi,
x<-matrix(0,80,ncol=1)
will create x matrix with all elements 0 (to be filled by the sums that you
need)
sum(y[y[,4]==1,5])
will calculate the sum of 5th column of y with 4th column=1
Similarly,
sum(y[y[,4]==80,5])
will calculate the sum of 5th column of y with 4th column=80.
You can
2 matches
Mail list logo