subFrame: A function for efficiently subsetting a multi-session...

View source: R/subFrame.R

subFrameR Documentation

A function for efficiently subsetting a multi-session "scrFrame" object.

Description

This function returns an "scrFrame" object containing only those sessions identified by "subs".

Usage

subFrame(scrFrame, subs)

Arguments

scrFrame

An scrFrame which will be subsetted. Must be of class 'scrFrame'.

subs

A numeris vector indicating which of the sessions are to be retained.

Value

An exact copy of the supplied scrFrame for only those session identified using the "subs" argument.

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (scrFrame, subs) 
{
    nms <- names(scrFrame)
    nms <- setdiff(nms, c("nocc", "type"))
    miss.nms <- setdiff(c("caphist", "traps", "trapCovs", "indCovs", 
        "trapOperation"), nms)
    scrFrame.sub <- list()
    for (i in nms) {
        scrFrame.sub[[i]] <- list()
        if (is.null(scrFrame[[i]])) {
            scrFrame.sub[[i]] <- NULL
        }
        else {
            for (j in 1:length(subs)) {
                scrFrame.sub[[i]][[j]] <- scrFrame[[i]][[subs[j]]]
            }
        }
    }
    for (i in miss.nms) {
        scrFrame.sub[[i]] <- NULL
    }
    new.nocc <- max(unlist(lapply(scrFrame.sum$caphist, function(x) dim(x)[3])))
    scrFrame.sub$nocc <- scrFrame$nocc
    scrFrame.sub$type <- scrFrame$type
    class(scrFrame.sub) <- "scrFrame"
    return(scrFrame.sub)
  }

jaroyle/oSCR documentation built on Sept. 23, 2023, 12:46 p.m.