Dear helpers,

 

I'm using R version 2.8.0.

Suppose that I have a small data set like below.

[,1] [,2] [,3] [,4]

a    1    1    0    0

b    0    1    1    0

c    1    1    1    0

d    0    1    1    1

 

First, I'd like to find row sum of values uniquely present in each row, but
only sequentially from the top row, meaning that if the value is shown in
the above row(s) already, the same value in the following row shouldn't be
added into the sum.

The result should be like this: 

 

row.sum

[1] 2 1 0 1

 

And if a and c were swapped, the row.sum is  3 0 0 1

 

Second, I'd like to randomly reorder the rows, and repeat calculating
row.sum again, for many times less than all combinations possible (4! In
this case), kind of simulation, and store the results into a matrix. 

Thanks.

Keun-Hyung

 

 

 

 


	[[alternative HTML version deleted]]

