Description Usage Arguments Details Value See Also Examples
Print values in a way that humans can easily understand.
1 2 3 4 |
x |
An object to print. |
both |
Show both, the |
digits |
For |
signif.digits |
Integer indicating the number of significant digits to be used, or |
round.digits |
Integer indicating the number of decimal places to be used, or |
format.params |
Parameters passed to |
At its core, pp
is a wrapper around signif
, round
, and format
. Currently, methods are defined for the following classes:
integer, numeric
matrix, array
data.frame (optionally, the “digits” parameters can be vectors, in which case a different value applies to each column of the data.frame)
table (output from table
and xtabs
)
lm, glm (prints odds ratios for logistic regression)
AsIs (output from I
)
list
pprop (output from pprop
– “pretty proportion”)
If a “digits” parameter is NA
, it is ignored. At most, only one non-NA “digits” parameter is used. Their order of precedence is: digits
, round.digits
, signif.digits
. By default, digits
and round.digits
are NA
.
pp
prints x
. Do not rely on the value, if any, that pp
might return.
print
, signif
, round
, format
, summary
.
Other pretty.print.functions: pp.pprop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ## Create a dataset
set.seed(42)
x.big = rnorm(12, mean=1e4, sd=1e3)
x.small = rnorm(12, mean=0, sd=0.5)
name = sample(levels(iris$Species), 12, replace=TRUE)
dd = data.frame(name, x.big, x.small)
pp(dd) # typical usage
pp(dd, b=TRUE) # show original and formatted
pp(dd, s=2) # 2 significant digits
pp(dd, r=2) # 2 decimal places
# 2 decimal places for small numbers (-1 to 1), 2 significant digits otherwise
pp(dd, d=2)
pp(dd, s=NA) # format only, don't round
pp(dd, r=-3) # round to the nearest thousand
# different signif.digits and round.digits for each column
pp(dd, s=c(NA, NA, 3), r=c(NA, 2, NA))
mm = tcrossprod(x.big, x.small)
pp(mm) # matrix
pp(qr(mm)) # list
flowers = sample(levels(iris$Species), 1e4, replace=TRUE)
pp(table(flowers)) # table
## Linear Models -- example from lm
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
summary(lm.D9)
pp(lm.D9) # cleaner output
## Logistic regression
## Create a dataset
set.seed(42)
n = 100
dd = data.frame(x1 = runif(n), x2 = runif(n))
dd = within(dd, {
x3 = 2 * x1 + x2 + rnorm(n)
A = factor(cut(x1, 3, FALSE))
B = factor(cut(x2, 3, FALSE))
y = factor(cut(x3, 2, FALSE))
})
gg = glm(y ~ A + B, data = dd, family = "binomial")
summary(gg)
pp(gg) # Odds ratios, 95% CI's
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.