R/sum.data.r

Defines functions sum.data

  sum.data = function(x, factors=c("trip", "set"), variable) {

    if (variable=="number") x[,variable] = 1  # create a dummy variable to allow counting of numbers
    m = as.data.frame.table(
          tapply( X=x[,variable],
                  INDEX=x[,factors],
                  FUN=sum,
                  simplify=T,
                  na.rm=T ) )
    names(m) = c(factors, paste(variable,"tot",sep="."))
    m = factor2character(m, factors)

    return(m)
  }
jae0/snowcrab documentation built on Nov. 6, 2024, 10:13 p.m.