Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Data After Specific Date

Tags:

date

r

I would like to be able to select dates from a data frame after or before a specific date. For example using quandl data on Gold prices.

pGold <- read.csv('http://www.quandl.com/api/v1/datasets/BUNDESBANK/BBK01_WT5511.csv?&trim_start=1968-04-01&trim_end=2014-01-08&sort_order=desc', colClasses=c('Date'='Date'))

pGold$asDate <- as.Date(pGold$Date)

head(pGold)
        Date   Value
1 2014-01-08 1226.50
2 2014-01-07 1237.50
3 2014-01-06 1238.00
4 2014-01-03 1232.25
5 2014-01-02 1219.75
6 2013-12-31 1201.50

plot(pGold[pGold$Date>"2012-01-01",], type="l", main="Price of Gold (USD)"))

enter image description here

like image 744
Francis Smart Avatar asked Jun 11 '26 15:06

Francis Smart


1 Answers

You've practically done it.

pGold <- read.csv('http://www.quandl.com/api/v1/datasets/BUNDESBANK/BBK01_WT5511.csv?&trim_start=1968-04-01&trim_end=2014-01-08&sort_order=desc', colClasses=c('Date'='Date'))
plot(subset(pGold,Date>"2012-01-01"),type="l")

gets you:

enter image description here

or if you want ggplot niceness:

ggplot(subset(pGold,Date>"2012-01-01"), aes(x=Date,y=Value))+geom_line()

gets you:

enter image description here

like image 154
Spacedman Avatar answered Jun 13 '26 05:06

Spacedman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!