head()

head()

The head() function is used to get the first rows of a vector or data frame. By default, it will print out the first 6 rows of the object, but you can also specify the number of rows you would like to print out.

The head() function is similar to the tail() function, however, the tail() function will print out the last 6 rows (or the number specified), instead of the first 6 rows (see the tail() function).

Example 1:

# Print out the first 6 rows of MindsetMatters

head( MindsetMatters )


Example output:
Example output of the head function showing the first six rows of MindsetMatters

Example 2:

# Print out the first 10 rows of MindsetMatters

head( MindsetMatters , 10)


Example output:
Example output of the head function showing the first ten rows of MindsetMatters

    • Related Articles

    • tail()

      The tail() function is used to get the last rows of a vector or data frame. By default, it will print out the last 6 rows of the object, but you can also specify the number of rows you would like to print out. The tail() function is similar to the ...
    • select()

      The select() function will select specific columns (variables) in a data frame. This may be useful when a data frame has many variables and you only want to take a look at a few of them together, or save a subset of variables as a new data frame. ...
    • recode()

      The recode() function can be used to rename any of the values of a variable. Example: # recode the variable `Year` and save it is a new column in the data frame Fingers$Year_recode <- recode(Fingers$Year, "1" = "First", "2" = "Second", "3" = "Third", ...
    • do()*

      The do()* function runs one or more lines of code the number of times specified inside the parentheses and returns the results as a data frame. Example 1: # take a random sample (n=10) of a variable, with replacement, # and calculate the standard ...
    • filter()

      The filter() function will find rows/cases where the conditions indicated are true. It is often used with operators such as the following: > (greater than) < (less than) >= (greater than or equal to) <= (less than or equal to) == (equal to) != (not ...