Skip to contents

This function takes a data frame and an optional number of rows to print from both the top (head) and bottom (tail) of the data frame. It is useful for quickly inspecting the first few and last few rows of a large data frame to understand its structure and contents.

Usage

ht(DF, NRows = 5)

Arguments

DF

A data frame to print. This parameter cannot be NULL.

NRows

Integer specifying the number of rows to print from both the head and tail of the data frame. Defaults to 5.

Value

The function is used for its side effect (printing) and does not return any value.

Author

Ahmed El-Gabbas

Examples

ht(mtcars)
#>       mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>     <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#>  1:  21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
#>  2:  21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
#>  3:  22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1
#>  4:  21.4     6 258.0   110  3.08 3.215 19.44     1     0     3     1
#>  5:  18.7     8 360.0   175  3.15 3.440 17.02     0     0     3     2
#> ---                                                                  
#> 28:  30.4     4  95.1   113  3.77 1.513 16.90     1     1     5     2
#> 29:  15.8     8 351.0   264  4.22 3.170 14.50     0     1     5     4
#> 30:  19.7     6 145.0   175  3.62 2.770 15.50     0     1     5     6
#> 31:  15.0     8 301.0   335  3.54 3.570 14.60     0     1     5     8
#> 32:  21.4     4 121.0   109  4.11 2.780 18.60     1     1     4     2

# -------------------------------------------

ht(DF = mtcars, 2)
#>       mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>     <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#>  1:  21.0     6   160   110  3.90 2.620 16.46     0     1     4     4
#>  2:  21.0     6   160   110  3.90 2.875 17.02     0     1     4     4
#> ---                                                                  
#> 31:  15.0     8   301   335  3.54 3.570 14.60     0     1     5     8
#> 32:  21.4     4   121   109  4.11 2.780 18.60     1     1     4     2

# -------------------------------------------

ht(DF = mtcars, 6)
#>       mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>     <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#>  1:  21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
#>  2:  21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
#>  3:  22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1
#>  4:  21.4     6 258.0   110  3.08 3.215 19.44     1     0     3     1
#>  5:  18.7     8 360.0   175  3.15 3.440 17.02     0     0     3     2
#>  6:  18.1     6 225.0   105  2.76 3.460 20.22     1     0     3     1
#> ---                                                                  
#> 27:  26.0     4 120.3    91  4.43 2.140 16.70     0     1     5     2
#> 28:  30.4     4  95.1   113  3.77 1.513 16.90     1     1     5     2
#> 29:  15.8     8 351.0   264  4.22 3.170 14.50     0     1     5     4
#> 30:  19.7     6 145.0   175  3.62 2.770 15.50     0     1     5     6
#> 31:  15.0     8 301.0   335  3.54 3.570 14.60     0     1     5     8
#> 32:  21.4     4 121.0   109  4.11 2.780 18.60     1     1     4     2