I'm trying to subtract one column(alldata$T3M.yld) from a whole dataframe(alldata.index) that contains two columns in one step if possible. How can I do that?
I can do this,
R.index = alldata.index$SPX - alldata$T3M.yld
R.index2 = alldata.index$RUS - alldata$T3M.yld
But I want it to be more like so
R.index = alldata.index - alldata$T3M.yld
This line doesnt work, gives me an error:
Error in
-.default
(alldata.index, alldata$T3M.yld) :
non-conformable arrays
Here is the data that I work with:
> head(alldata.index)
SPX RUS
2013-09-03 4.155575e-03 0.0052881849
2013-09-04 8.084188e-03 0.0091290315
2013-09-05 1.209132e-03 0.0030278274
2013-09-06 5.442973e-05 0.0008357704
2013-09-09 9.943282e-03 0.0159279413
2013-09-10 7.318940e-03 0.0091731686
> head(alldata$T3M.yld)
T3M.yld
2013-09-01 NA
2013-09-03 2e-04
2013-09-04 2e-04
2013-09-05 2e-04
2013-09-06 2e-04
2013-09-09 2e-04
So I want SPX-T3M.yld and RUS-T3M.yld and store it all in R.index in one step. Hope it makes sense what i'm trying to do.
P.S. The reason I dont want to do it separately and then combine in it to one dataframe is because i try to automate this process and i will pass different data to alldata.index, so next time I might have 5 columns instead of 2.
Please let me know if you have any questions so I can clarify. I couldn't find a solution in google(surprisingly). Thank you.