Skip to content
Prev 201097 / 398503 Next

consecutive numbering of elements in a matrix

if I understand what you want correctly, then one approach is:

A <- matrix(sample(50, 21), 7, 3)
A[sample(21, 5)] <- NA

A
row(A) - apply(is.na(A), 2, cumsum)

I hope it helps.

Best,
Dimitris
Jim Bouldin wrote: