R/speciescount.R

Defines functions speciescount

Documented in speciescount

speciescount <-
function (dat, orderby = "Species") 
{
    spp <- unique(dat$Species)
    nsp <- {
    }
    for (i in 1:length(spp)) {
        fsp <- which(dat$Species == spp[i])
        sp <- dat[fsp, ]
        n <- nrow(sp)
        excl <- sum(sp$Exclude)
        nu <- n - excl
        d <- data.frame(Species = spp[i], ntot = n, nuniq = nu)
        nsp <- rbind(nsp, d)
    }
    if (orderby == "ntot") {
        f <- order(nsp$ntot, decreasing = TRUE)
        nsp <- nsp[f, ]
    }
    if (orderby == "nuniq") {
        f <- order(nsp$nuniq, decreasing = TRUE)
        nsp <- nsp[f, ]
    }
    if (orderby == "Species") {
        f <- order(spp)
        nsp <- nsp[f, ]
    }
    return(nsp)
}

Try the biogeo package in your browser

Any scripts or data that you put into this service are public.

biogeo documentation built on May 29, 2017, 10:55 a.m.