data.table (version 1.0)

as.data.table.matrix: ~~function to do ... ~~

Description

~~ A concise (1-5 lines) description of what the function does. ~~

Usage

as.data.table.matrix(x, keep.rownames = FALSE)

Arguments

x
~~Describe x here~~
keep.rownames
~~Describe keep.rownames here~~

Value

  • ~Describe the value returned If it is a LIST, use
  • comp1Description of 'comp1'
  • comp2Description of 'comp2'
  • ...

Warning

....

Details

~~ If necessary, more details than the __description__ above ~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as ~~fun~~, ~~~

Examples

Run this code
##---- 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(x, keep.rownames=FALSE)
{
    if (keep.rownames) return(data.table(rn=rownames(x), x, keep.rownames=FALSE))
    d <- dim(x)
    nrows <- d[1]
    ir <- seq(length = nrows)
    ncols <- d[2]
    ic <- seq(length = ncols)
    dn <- dimnames(x)
    collabs <- dn[[2]]
    if (any(empty <- nchar(collabs) == 0)) 
        collabs[empty] <- paste("V", ic, sep = "")[empty]
    value <- vector("list", ncols)
    if (mode(x) == "character") {
        for (i in ic) value[[i]] <- as.factor(x[, i])       # for efficiency.
    }
    else {
        for (i in ic) value[[i]] <- as.vector(x[, i])       # to drop any row.names that would otherwise be retained inside every column of the data.table
    }
    if (length(collabs) == ncols) 
        names(value) <- collabs
    else
        names(value) <- paste("V", ic, sep = "")
    class(value) <- "data.table"
    value
  }

Run the code above in your browser using DataCamp Workspace