选择特定日期之后的数据 [英] Select Data After Specific Date
本文介绍了选择特定日期之后的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够从数据框中选择特定日期之前或之后的日期。例如,使用有关黄金价格的数量数据。
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)"))
推荐答案
您实际上已经做到了。
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")
让您:
或者如果您想要 ggplot
精美程度:
or if you want ggplot
niceness:
ggplot(subset(pGold,Date>"2012-01-01"), aes(x=Date,y=Value))+geom_line()
让您:
这篇关于选择特定日期之后的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文