在R-日期范围中选择特定数据

时间:2014-12-25 13:07:21

标签: r datepicker dataframe quantmod

我是 R 的新手,我正在尝试从2013-05-01选择某些数据范围并绘制它。但是,下载的数据是从2007年开始的-01-03 。但我想排除前六年并绘制2013年5月的数据。 我可以这样做吗?我使用了日期功能,但我猜这不起作用。 任何人都可以帮我解决这个问题吗?

PS:附上了代码。

library(quantmod)
library(tseries)
library(FinCal)
#downloading data

getSymbols('DRYS')
retdrys<-diff(DRYS$DRYS.Adjusted)/DRYS$DRYS.Adjusted
retdrys[is.na(retdrys)]<-0
#plot data from 2013-05-01
plot(retdrys,date>"2013-05-01") 

我可以从头开始绘制数据,但如果我必须绘制一定范围的数据,我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以使用chartSeries中的PerformanceAnalytics。此绘图函数有一个很好的内置参数subset,可用于指定日期范围。

以下是一些例子:

require(PerformanceAnalytics)
chartSeries(retdrys,subset = c('2013-04','2014'))  #Plot from April 2013 to the end of 2014
chartSeries(retdrys,subset = '2011')  #Plot from the beginning to the end of 2011
chartSeries(retdrys,subset = '2010-08') #Plot only for the month of August