[R] row sum with all absence in a presence-absence matrix

arun smartpink111 at yahoo.com
Tue Oct 8 14:38:15 CEST 2013


mat1<- matrix(sample(0:1,15*100,replace=TRUE),nrow=15,ncol=100,dimnames=list(LETTERS[1:15],paste0("D",sprintf("%04d",1:100))))
 rowSums(mat1[rownames(mat1)%in% c("A","D","L"),])
# A  D  L 
#44 55 50 

----- Original Message -----
From: Elaine Kuo <elaine.kuo.tw at gmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Sent: Tuesday, October 8, 2013 7:21 AM
Subject: [R] row sum with all absence in a presence-absence matrix

Dear list

I have a matrix composed of islandID as rows and speciesID as columns.

IslandID: Island A, B, C….O (15 islands in total)

SpeciesID: D0001, D0002, D0003….D0100 (100 species in total)

The cell of the matrix describes presence (1) or absence (0) of the species
in an island.

Now I would like to search how many species are found in (1, presence) for
Island A, Island D, and Island L respectively.

Please kindly advise the R code for the search purpose.

Thank you.

    [[alternative HTML version deleted]]

R-help at r-project.org mailing list
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