R/print.poplab.R

print.poplab <-
function (x, option, year, folder, ...) 
{
    require(MASS)
    if (option == "current") {
        pop.t <- x[[2]]
        colnames(pop.t) <- c("ID", "yob", "sex", "m", "f", "yod", 
            "yoi")
        pop.t <- pop.t[pop.t[, "yob"] <= year, ]
    }
    if (option == "base") {
        if (is.null(dim(x)[2])) 
            pop.t <- x[[1]]
        if (!is.null(dim(x)[2])) 
            pop.t <- x
    }
    where <- switch(option, base = paste("base_pop_", year, ".txt", 
        sep = ""), current = paste("simpop_endYr_", year, ".txt", 
        sep = ""))
    write.matrix(pop.t, file = file.path(folder, where), sep = " ")
    cat("Data saved to", folder, "folder as", where, "file \n")
}

Try the poplab package in your browser

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

poplab documentation built on May 2, 2019, 5:53 p.m.