How to disable data.table names below?

I am running Rstudio 0.99.489 and R-3.2.3 on Windows 7

How can I avoid printing V1 and N at the bottom of the data?

options(datatable.print.nrows = Inf)
dt <- data.table(sample.int(2e3, 1e4, T))
print(dt[ , .(.N), V1])

...
1980:  419  1
1981:  898  2
1982: 1260  1
        V1  N
+4
source share
2 answers

You can manipulate the printing of an object as an ordinary character vector.

library(data.table)
options(datatable.print.nrows = Inf)
dt = data.table(sample.int(2e3, 1e4, T))
myprint = function(x){
    prnt = capture.output(print(x))
    cat(prnt[-length(prnt)], sep="\n")
}
myprint(dt[ , .(.N), V1])
+5
source

Here we consider an alternative. Since s is data.tableextended data.frame, why not just use the method printfor data.frames? This way you both print all the input lines, but without the column names, which also appear at the bottom.

For example, the following dataset is enough to demonstrate the behavior of print names below.

set.seed(1)
dt <- data.table(sample(21, 1000, TRUE)) ## Sufficient to demonstrate behavior
dt[, .N, by = V1]                        ## Shows the names at the bottom

print.data.frame, :

print.data.frame(dt[, .N, by = V1])      ## Specify use of data.frame print method

, -, data.table, - :

setDF(dt[, .N, by = V1])[]                ## dt stays a `data.table`
+2

Source: https://habr.com/ru/post/1622082/


All Articles