[R] finding row and column names of a matrix
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Fri Oct 8 09:25:39 CEST 2010
try this:
mat <- matrix(rnorm(20), 5, 4,
dimnames = list(letters[1:5], LETTERS[1:4]))
mat[sample(20, 4)] <- NA
ind <- which(is.na(mat), arr.ind = TRUE)
mat
cbind(RowName = rownames(mat)[ind[, 1]],
ColName = colnames(mat)[ind[, 2]])
I hope it helps.
Best,
Dimitris
On 10/8/2010 7:09 AM, Data Analytics Corp. wrote:
> Hi,
>
> Suppose I have a 3X4 matrix with row names TL, JAR and TM and column
> names A, B, C, D. The cell in the first row, third column has an NA. I
> want to find the row and column NAMES corresponding to that cell with
> the NA. Obviously, I want to extend this to any matrix of any size that
> has one or more cells with NAs. Any suggestions?
>
> Thanks,
>
> Walt
>
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> walt at dataanalyticscorp.com
> www.dataanalyticscorp.com
>
> _____________________________________________________
>
>
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
More information about the R-help
mailing list