[R-SIG-Finance] align time series correctly
Joshua Ulrich
josh.m.ulrich at gmail.com
Wed Dec 29 21:08:28 CET 2010
Use merge.xts:
require(quantmod)
getSymbols("^IRX;^VIX;SPY", from="1994-01-01")
Data <- merge(IRX,VIX,SPY)
# Note that there will be some NAs
# e.g. 1994-01-17 for IRX
head(Data,20)
# use na.omit to drop them
Data <- na.omit(Data)
nrow(Data) # 4256
# or use merge's 'all' arg
Data <- merge(IRX,VIX,SPY,all=FALSE)
nrow(Data) # same as na.omit
Best,
--
Joshua Ulrich | FOSS Trading: www.fosstrading.com
On Wed, Dec 29, 2010 at 1:53 PM, Lei Jin <leijin56 at gmail.com> wrote:
> I am trying to create a data frame that includes data from 3 time series.
> (^IRX, ^VIX, SPY). I noticed that getSymbols() from yahoo (default) seems
> to retrieve different rows for the 3 time series for the same time window I
> specified. So, I got an "arguments imply differing number of rows". My
> simple questions is how do I set # of rows for all 3 time series to be equal
> and aligned by date correctly.
>
>
> ==============================================================
> arguments imply differing number of rows: 4279, 4277, 4258
> In addition: Warning message:
> In log(x) : NaNs produced
>> print(NROW(IRX))
> [1] 4258
>> print(NROW(VIX))
> [1] 4277
>> print(NROW(SPY))
> [1] 4279
>
> --
> Thank you,
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>
More information about the R-SIG-Finance
mailing list