[R] matrix help (first occurrence of variable in column)

Michael Denslow michael.denslow at gmail.com
Wed May 18 15:37:52 CEST 2011


Dear R help,
Apologies for the less than informative subject line. I will do my
best to describe my problem.

Consider the following matrix:

mdat <- matrix(c(1,0,1,1,1,0), nrow = 2, ncol=3, byrow=TRUE,
               dimnames = list(c("T1", "T2"),
                               c("sp.1", "sp.2", "sp.3")))

mdat

In my actual data I have time (rows) and species occurrences (0/1
values, columns). I want to count the number of new species that occur
at a given time sample. For the matrix above the answer would be 1.

Is there a simple way to figure out if the species has never occurred
before and then sum them up?

Thanks in advance,
Micheal

-- 
Michael Denslow

I.W. Carpenter Jr. Herbarium [BOON]
Department of Biology
Appalachian State University
Boone, North Carolina U.S.A.
-- AND --
Communications Manager
Southeast Regional Network of Expertise and Collections
sernec.org

36.214177, -81.681480 +/- 3103 meters



More information about the R-help mailing list