[R] to retrieve specific data from a matrix

Berend Hasselman bhh at xs4all.nl
Wed Sep 11 09:50:58 CEST 2013


On 11-09-2013, at 09:38, Elaine Kuo <elaine.kuo.tw at gmail.com> wrote:

> 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.

What have you tried?
Something like this perhaps

which(datamatrix[2,] == 1) or which(datamatrix[2,] == 1L)

Berend



More information about the R-help mailing list