[datatable-help] print.data.table's digits argument
Frank Erickson
FErickson at psu.edu
Mon Jun 17 23:12:55 CEST 2013
Hi,
I have a data.table with list and float columns. I want to print it with
the floats rounded to display only a few significant digits. Using
getAnywhere(print.data.table), I see that digits is an option. However,
when I use it, it seems to have no effect. Is there a special way to pass
arguments to hidden functions like this (on the methods(print) list it
shows up as print.data.table*)?
Anyway, here are the first two lines of my dt:
DT <- structure(list(fisyr = 1995:1996, er = list(c(1, 3), c(1, 3)),
eg = c(0.0197315833926059, 0.0197315833926059), esal = list(
c(2329.89763779528, 2423.6811023622), c(2263.07456978967,
2354.16826003824)), fr = list(c(4, 4), c(4, 4)), fg =
c(0.039310363070415,
0.039310363070415), fsal = list(c(2520.85433070866, 2520.85433070866
), c(2448.55449330784, 2448.55449330784)), mr = list(c(5,
30), c(5, 30)), mg = c(0.0197779376457164, 0.0197779376457164
), msal = list(c(2571.70078740157, 4215.73622047244),
c(2497.94263862333,
4094.82600382409))), .Names = c("fisyr", "er", "eg", "esal",
"fr", "fg", "fsal", "mr", "mg", "msal"), class = c("data.table",
"data.frame"), row.names = c(NA, -2L))
print(DT,digits=4)
# just DT
print.data.frame(DT,digits=4)
# fisyr er eg esal fr fg fsal mr mg
msal
# 1 1995 1, 3 0.01973 2330, 2424 4, 4 0.03931 2521, 2521 5, 30 0.01978
2572, 4216
# 2 1996 1, 3 0.01973 2263, 2354 4, 4 0.03931 2449, 2449 5, 30 0.01978
2498, 4095
Printing as a data.frame does the rounding/shortening, but the list columns
look ugly (thanks to that extra space), so I'd rather see a data.table
output.
It's a tiny data.table, so if anyone knows a fancy lapply trick for this,
that'd be cool. I'm going to try to find one myself now.
Thanks,
Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130617/a209566c/attachment.html>
More information about the datatable-help
mailing list