head( )

Preview the first rows of an object. head() is a base R function.

Required Library

# head() is part of base R — no package installation needed

Syntax

head(x)
head(x, n = 3)

head(x) shows the first 6 rows of a data frame or tibble by default. Use n to choose a different number of rows.

Use head() when you want a quick preview of the top of a data set. It is handy right after import and is good practice when inspecting large data sets.

Examples

Preview the first rows of tablet weights
Show only the first 3 rows
Show the last rows with tail()

tail() works like head(), but it shows the last rows instead of the first rows.

Argument Overview

Required arguments must be included when using a function while optional arguments can be included on demand.

x — object to preview vector | matrix | data frame | tibble Required

The object to preview. head() is most commonly used with data frames and tibbles, but it also works with vectors and matrices.

head(tablet_weights)

Data Types: vector | matrix | data.frame | tibble

n — number of rows to show integer Optional

The number of rows to return from the start of the object. Default is 6.

head(tablet_weights, n = 3)

Data Types: integer · Default: 6