R/subsetcomm.R

Defines functions `subsetcomm`

`subsetcomm` <-
function(x, y, factor, level, returncomm=TRUE) {
    subs <- y[,factor]==level
    for (q in 1:length(subs)) {
        if(is.na(subs[q])) {subs[q]<-F}
    }
    if (returncomm==T) {
        x <- x[subs, , drop=F]
        freq <- apply(x,2,sum)
        subs <- freq>0
        x <- x[,subs,drop=F]
        return(x)
    }else{
        y <- y[subs,,drop=F]
        for (i in 1:ncol(y)) {
            if (is.factor(y[,i])) {y[,i] <- factor(y[,i][drop=T])}
        }
        return(y)
    }
}

Try the BiodiversityR package in your browser

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

BiodiversityR documentation built on Oct. 22, 2023, 5:06 p.m.