[R] search species with all absence in a presence-absence matrix

arun smartpink111 at yahoo.com
Sat Sep 21 02:57:37 CEST 2013


Hi,
Try this:

 set.seed(248)
 lst1<- lapply(1:1000,function(i) matrix( sample(0:1,15*100,replace=TRUE),ncol=100,dimnames=list(paste("Island",LETTERS[1:15]),  paste0("D",sprintf("%04d",1:100)))))
 lst2<-lst1[sapply(lst1,function(x) any(colSums(x)==0))]
##The above steps are just to create some matrices with zeros in all the "islands"
mat1<-lst2[[1]]
 mat1[,colSums(mat1)==0,drop=FALSE]
#         D0038
#Island A     0
#Island B     0
#Island C     0
#Island D     0
#Island E     0
#Island F     0
#Island G     0
#Island H     0
#Island I     0
#Island J     0
#Island K     0
#Island L     0
#Island M     0
#Island N     0
#Island O     0
colnames(mat1)[colSums(mat1)==0]
#[1] "D0038"
 mat2<-lst2[[3]]
 colnames(mat2)[colSums(mat2)==0]
#[1] "D0086"

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: Friday, September 20, 2013 7:14 PM
Subject: [R] search species 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 the species with absence (0)

in all the islands (Island A to Island O.)



Please kindly advise the R code for the search purpose.

Thank you.



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