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.
Este exercício faz parte do curso
Intermediate R for Finance
Instruções do exercício
- 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 thedate
column, and assign it tostocks
as the column,weekday
. - View
stocks
now. 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()
onapple
as your condition. Assign this new data frame tostocks_no_NA
. - Now, you are interested in days where
apple
was above117
, or whenmicr
was above63
. Use relational operators,|
, andsubset()
to accomplish this withstocks_no_NA
.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# View stocks
___
# Weekday investigation
stocks$weekday <-
# View stocks again
___
# Remove missing data
stocks_no_NA <- ___
# Apple and Microsoft joint range
___