Elaine Kuo
2013-Oct-08 11:21 UTC
[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]]
On 10/08/2013 10:21 PM, Elaine Kuo wrote:> 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. >Hi Elaine, Sounds like "rowSums" to me. Jim
Hi,
Try:
set.seed(49)
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
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: 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
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.