[R] consecutive numbering of elements in a matrix

Jim Bouldin jrbouldin at ucdavis.edu
Sun Nov 22 20:42:12 CET 2009


Thank you Dimitris, that solves it exactly!  I continue to be amazed at how
a single line of code can be so powerful in R, containing so much
information.  Hard as hell to interpret though (for me).
Jim

> one approach is the following:
> 
> B <- cbind(c(1:6, NA), c(1:3, NA,NA,NA, 4), c(1:3, NA,NA, 4,5))
> matrix(B[order(col(B), B)], nrow(B), ncol(B))
> 
> 
> I hope it helps.
> 
> Best,
> Dimitris


Jim Bouldin, PhD
Research Ecologist
Department of Plant Sciences, UC Davis
Davis CA, 95616
530-554-1740




More information about the R-help mailing list