This function selects several top and bottom rows of a data frame for a preview.

head_tail(
  obj,
  n = 4,
  format = c("f", "g", "e"),
  sep = "...",
  max_decimals = NULL,
  signif_digits = 3,
  tolerance = 2,
  top = n,
  bottom = n
)

Arguments

obj

A data frame.

n

(integer) Number of top and bottom rows to display.

format

equal to "d" (for integers), "f", "e", "E", "g", "G", "fg" (for reals), or "s" (for strings). Default is "d" for integers, "g" for reals.

"f" gives numbers in the usual xxx.xxx format; "e" and "E" give n.ddde+nn or n.dddE+nn (scientific format); "g" and "G" put x[i] into scientific format only if it saves space to do so and drop trailing zeros and decimal point - unless flag contains "#" which keeps trailing zeros for the "g", "G" formats.

"fg" (our own hybrid format) uses fixed format as "f", but digits as the minimum number of significant digits. This can lead to quite long result strings, see examples below. Note that unlike signif this prints large numbers with more significant digits than digits. Trailing zeros are dropped in this format, unless flag contains "#".

sep

(character) Separator between displayed top and bottom lines.

max_decimals

(integer, NULL) Maximum number of decimal digits to bpint. If NULL, no restrictions applied.

signif_digits

(integer, NULL) Number of significant digits used to determine appropriate rounding. If NULL, all digits are used to determine the appropriate rounding.

tolerance

(integer) For small datasets, number of rows to show in addition to top and bottom before the dataset is truncated.

top

(integer) Number of top rows to display.

bottom

(integer) Number of bottom rows to display.

Value

A truncated data frame (which is intended to be printed) with all variables converted to strings.

Examples

library(biostat) data(swiss) head_tail(swiss)
#> Fertility Agriculture Examination Education Catholic #> Courtelary 80.2 17.0 15 12 9.96 #> Delemont 83.1 45.1 6 9 84.84 #> Franches-Mnt 92.5 39.7 5 5 93.40 #> Moutier 85.8 36.5 12 7 33.77 #> ... ... ... ... ... ... #> ValdeTravers 67.6 18.7 25 7 8.65 #> V. De Geneve 35.0 1.2 37 53 42.34 #> Rive Droite 44.7 46.6 16 29 50.43 #> Rive Gauche 42.8 27.7 22 29 58.33 #> #> Infant.Mortality #> Courtelary 22.2 #> Delemont 22.2 #> Franches-Mnt 20.2 #> Moutier 20.3 #> ... ... #> ValdeTravers 19.5 #> V. De Geneve 18.0 #> Rive Droite 18.2 #> Rive Gauche 19.3 #>
data(swiss) head_tail(iris, n = 2)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> ... ... ... ... ... ... #> 149 6.2 3.4 5.4 2.3 virginica #> 150 5.9 3.0 5.1 1.8 virginica #>
head_tail(iris[1:6, ], n = 2, tolerance = 1)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> ... ... ... ... ... ... #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa #>
head_tail(iris[1:6, ], n = 2, tolerance = 2)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa #> 6 5.4 3.9 1.7 0.4 setosa #>