df.head: Print the First and Last Rows of a Data Frame

View source: R/df.head.R

df.headR Documentation

Print the First and Last Rows of a Data Frame

Description

The function df.head prints the first rows of a data frame and the function df.tail prints the last rows of a data frame and prints as many columns as fit on the console supplemented by a summary of the remaining rows and columns.

Usage

df.head(data, n = 6, digits = 3, width = 20, factor.labels = TRUE,
        row.names = TRUE, row.names.col = "gray2", message = TRUE,
        message.col = "b.blue", check = TRUE, output = TRUE)

df.tail(data, n = 6, digits = 3, width = 20, factor.labels = TRUE,
        row.names = TRUE, row.names.col = "gray2", message = TRUE,
        message.col = "b.blue", check = TRUE, output = TRUE)

Arguments

data

a data frame.

n

a numeric value indicating the number of rows to be printed on the console.

digits

a numeric value indicating the maximum number of decimal places to be used.

width

a numeric value indicating the maximum width of the character strings in the vector.

factor.labels

logical: if TRUE, factor labels will be printed on the console.

row.names

logical: if TRUE, row names of the data frame are printed on the console.

row.names.col

a character string indicating the text color for the row names, see color argument of the chr.color function.

message

logical: if TRUE, number of remaining rows and columns are printed on the console.

message.col

a character string indicating the text color for the number of remaining rows and columns printed on the console, see color argument of the chr.color function.

check

logical: if TRUE (default), argument specification is checked.

output

logical: if TRUE (default), output is shown on the console.

Value

Returns a list with following entries:

df

data frame specified in data with the first or last n rows of the data frame with as many columns as fit on the console

row.col

character string indicating the remaining rows and columns

Author(s)

Takuya Yanagida

See Also

df.check, head, tail, freq, descript

Examples

# Example 1: Print first and last six rows
df.head(mtcars)
df.tail(mtcars)

# Example 2: Print first and last six rows without row names
df.head(mtcars, row.names = FALSE)
df.tail(mtcars, row.names = FALSE)

# Example 3: Print first and last three rows with one max. number of decimal places
df.head(mtcars, n = 3, digits = 1)
df.head(mtcars, n = 3, digits = 1)

misty documentation built on April 4, 2025, 3:49 a.m.

Related to df.head in misty...