选择特定日期后的数据

Fra*_*art 2 r date

我希望能够在特定日期之后或之前从数据框中选择日期.例如,使用关于黄金价格的quandl数据.

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)"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Spa*_*man 6

你几乎已经完成了它.

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")
Run Code Online (Sandbox Code Playgroud)

得到你:

在此输入图像描述

或者如果你想要ggplot好看:

ggplot(subset(pGold,Date>"2012-01-01"), aes(x=Date,y=Value))+geom_line()
Run Code Online (Sandbox Code Playgroud)

得到你:

在此输入图像描述