R/data2mat.R

data2mat <-
function(data = data)
{ 
    if (!any(colnames(data) == "abundance"))
        stop("A column named \"abundance\" must be speciefied.")
    if (!any(is.integer(data$abundance)))
        stop("Number of individuals must be integer!")
    col <- which(colnames(data) == "abundance")
    data1 <- data[,-col]
    abundance <- as.numeric(data[,col])
    result1 <- data.frame(rep(NA, sum(abundance)))
    colnames(result1) <- "plots"
    for (i in 1:(ncol(data)-1)){
        result1[, i] <-  rep(as.character(data[, i]), abundance)
    }
    result <- table(result1)
    return(result)
}

Try the spaa package in your browser

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

spaa documentation built on May 2, 2019, 9:44 a.m.