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, usehead(cash, n = ___)tail()- Returns the last few rows of a data frame. By default, 6. To change this, usetail(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!
Latihan ini adalah bagian dari kursus
Introduction to R for Finance
Petunjuk latihan
- Call
head()oncashto see the first 4 rows. - Call
tail()oncashto see the last 3 rows. - Call
str()oncashto check out the structure of your data frame. (You might notice that the class ofcompanyis aFactorand not acharacter. Do not fear! This will be covered in Chapter 4. For now, don't worry about it.)
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Call head() for the first 4 rows
# Call tail() for the last 3 rows
# Call str()