Skip to content

Data frames

1 message · Liaw, Andy

#
data.matrix() might be a safer choice...
If the columns are all numerics, you can create a matrix with the appriate
column names and 0 rows, then coerce to data frame:

emptyData <- function(varNames) {
    m <- matrix(numeric(0), ncol=length(varNames),
                dimnames=list(NULL, varNames))
    as.data.frame(m)
}

Yet another possibility is to construct the 0-row data frame
directly by giving 0-length named arguments to data.frame().

Andy