Get Started

Making head()s and tail()s of your data with some str()ucture

Time to introduce a few simple, but very useful functions.

  • head() - Returns the first few rows of a data frame. By default, 6. To change this, use head(cash, n = ___)
  • tail() - Returns the last few rows of a data frame. By default, 6. To change this, use tail(cash, n = ___)
  • str() - Check the structure of an object. This fantastic function will show you the data type of the object you pass in (here, data.frame), and will list each column variable along with its data type.

With a small data set such as yours, head() and tail() are not incredibly useful, but imagine if you had a data frame of hundreds or thousands of rows!

This is a part of the course

“Introduction to R for Finance”

View Course

Exercise instructions

  • Call head() on cash to see the first 4 rows.
  • Call tail() on cash to see the last 3 rows.
  • Call str() on cash to check out the structure of your data frame. (You might notice that the class of company is a Factor and not a character. Do not fear! This will be covered in Chapter 4. For now, don't worry about it.)

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Call head() for the first 4 rows


# Call tail() for the last 3 rows


# Call str()
Edit and Run Code