Whenever I format a table as such:
example <- sample(LETTERS, replace = T)
format(table(example), scientific = T)
The numbers become characters. How can I tell format()
my object is numeric without resorting to as.numeric()
? I can't find any such parameters in the function's help page. It says that format()
objects are usually numeric, so I guess I'm missing some basic command.
My real data looks like this:
> xtabs(...)
PRU/DF PSU/ILH PSU/JFA PSU/MCL PSU/SRM PSU/ULA
1.040771e+01 0.000000e+00 2.280347e-01 0.000000e+00 0.000000e+00 8.186240e+00
PSU/URA PSU/VGA PU/AC PU/AM PU/AP PU/BA
0.000000e+00 1.534169e+01 8.184747e+01 1.410106e+01 1.028717e+01 1.099289e+00
PU/GO PU/MA PU/MG PU/MT PU/PA PU/PI
0.000000e+00 4.369910e+01 5.350849e+00 0.000000e+00 4.706721e-01 0.000000e+00
I want to have the console print the numbers prettier so my co-workers don't have a heart attack. This is what I've come up with:
> format(xtabs(...), scientific = F, digits = 1)
PRU/DF PSU/ILH PSU/JFA PSU/MCL PSU/SRM PSU/ULA PSU/URA PSU/VGA
"10.4077" " 0.0000" " 0.2280" " 0.0000" " 0.0000" " 8.1862" " 0.0000" "15.3417"
PU/AC PU/AM PU/AP PU/BA PU/GO PU/MA PU/MG PU/MT
"81.8475" "14.1011" "10.2872" " 1.0993" " 0.0000" "43.6991" " 5.3508" " 0.0000"
PU/PA PU/PI PU/RO PU/RR PU/TO PRU/RJ PSU/CPS PSU/NRI
" 0.4707" " 0.0000" "40.6327" "10.3247" " 0.0000" "10.9644" " 0.0000" "55.4122"
I'd like to get rid of those quotes so the data looks better on the console.