Learn R Programming

misty (version 0.7.0)

df.head: 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(x, n = 6, digits = 3, width = 20, row.names = TRUE,
        row.names.col = "gray2", message = TRUE, message.col = "b.blue",
        check = TRUE, output = TRUE)

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

Value

Returns a list with following entries:

df

data frame specified in x 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

Arguments

x

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.

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.

Author

Takuya Yanagida

See Also

df.check, head, tail, freq, descript

Examples

Run this code
# 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)

Run the code above in your browser using DataLab