1. Data frame manipulation
Manipulating, accessing, and subsetting data frames deserves its own video because there are so many ways to slice and dice your data.
2. Data frame subsets
In terms of the basics, everything is pretty much the same as accessing elements in a matrix. You can use the brackets to select rows and columns from your data frame. Here, we are selecting rows 3 through 6 of debt. One thing to look out for is the simplification that happens when you select a single column. Selecting the first three rows of just the payment column simplifies the result into a vector. If you want to keep this as a data frame, you just need to add 'drop equals F' or FALSE inside the brackets. A common manipulation with data frames is to select an entire column to work with. This happens so often that it has its own shortcut. Typing in the name of a data frame followed by a dollar sign and then the name of the column you are after allows you a clean way to return just that information. Here, we are selecting just the payment column of the data frame. Again, be aware that R has simplified the result to a vector.
3. Subset() for more power
When you want to create more complex subsets, or subset on a condition, the next step up is to use the 'subset' function. For example, what if you wanted to look at just Dan's debt to total it up? You could use the brackets to select just rows 1 through 3, but this is not very robust against any changes to the data set. A better way to do this is to use subset to tell R that you just want the rows of debt where name equals "Dan". The double equals sign there is known as a relational operator, and will be covered fully in the next course, Intermediate R for Finance. However, for this example, its intentions should be pretty intuitive. We can also subset on numeric columns. To just see rows where payment equals 100 dollars, you would do the following. One of the coolest things about this form is that the code is readable from left to right in plain english. You want to subset the debt data frame where payment equals 100. This makes it much easier for others to understand your code.
4. Let's practice!
That's all for now. Go try out your new skills on manipulating data frames!