CommencerCommencer gratuitement

Accessing and subsetting data frames (2)

As you might imagine, selecting a specific column from a data frame is a common manipulation. So common, in fact, that it was given its own shortcut, the $. The following return the same answer:

cash$cash_flow

[1] 1000 4000  550 1500 1100  750 6000

cash[,"cash_flow"]

[1] 1000 4000  550 1500 1100  750 6000

Useful right? Try it out!

Cet exercice fait partie du cours

Introduction to R for Finance

Afficher le cours

Instructions

  • Select the "year" column from cash using $.
  • Select the "cash_flow" column from cash using $ and multiply it by 2.
  • You can delete a column by assigning it NULL. Run the code that deletes "company".
  • Now print out cash again.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Select the year column


# Select the cash_flow column and multiply by 2


# Delete the company column
cash$company <- NULL

# Print cash again
Modifier et exécuter le code