All together now!
Great! You have learned a lot about operators and subsetting. This will serve you well in future data analysis projects. Let's do one last exercise that combines a number of operators together.
A new version of the stocks data frame is available for you to use.
Cet exercice fait partie du cours
Intermediate R for Finance
Instructions
- First, print
stocks. It contains Apple and Microsoft prices for December, 2016. - It seems like you have missing data. Let's investigate further. Use
weekdays()on thedatecolumn, and assign it tostocksas the column,weekday. - View
stocksnow. The missing data is on weekends! This makes sense, the stock market is not open on weekends. - Remove the missing rows using
subset(). Use!is.na()onappleas your condition. Assign this new data frame tostocks_no_NA. - Now, you are interested in days where
applewas above117, or whenmicrwas above63. Use relational operators,|, andsubset()to accomplish this withstocks_no_NA.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# View stocks
___
# Weekday investigation
stocks$weekday <-
# View stocks again
___
# Remove missing data
stocks_no_NA <- ___
# Apple and Microsoft joint range
___