[R] to retrieve specific data from a matrix

arun smartpink111 at yahoo.com
Wed Sep 11 14:35:10 CEST 2013


Hi,
set.seed(24)
mat1<- matrix(sample(0:1,20*100,replace=TRUE),ncol=100,dimnames=list(paste0("Species",1:20),paste0("Species",1:100)))
 which(mat1[1,]==1)
#or
which(!is.na(match(mat1[1,],1)))
A.K.




----- Original Message -----
From: Elaine Kuo <elaine.kuo.tw at gmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Wednesday, September 11, 2013 3:38 AM
Subject: [R] to retrieve specific data from a matrix

Dear list,

I want to retrieve a specific data from a matrix with 3000 columns.
The matrix has island ID as its rows and species ID as its columns.
There are 20 rows and 3000 columns in the matrix.
(Island ID: Species 1- Species 20/ species ID: Species 1- Species 3000)
The contents of the matrix grids is 1 or 0, for presence and absence.

Now I would like to check in Island 1 which species is 1. (Island 1 as row
2)
Please kindly advise how to code the command and thank you in advance.

Elaine

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list