Using transform
for example, you can create a new column like this:
obj <- merge(foo, footoo, all = FALSE)
transform(obj, newfoo = foo/footoo )
Question
I have two series that I have joined in a single xts object using merge(foo, footoo, all = FALSE)
.
Now I need to take a new vector = foo/footoo :
I'm trying to avoid use of cbind
because I can't bring myself to haphazardly join an unindexed vector of data to my safely ordered xts object.
Do I need to coerce to something like data.frame (for which I would know how to do this)? But if so, how do I keep my index intact? It's the ordering that has me nervous.
I'm very new to R and this is the first time I've worked with time series in R, so I apologize if this question has an answer that is obvious to all but me.
Thanks in advance.
Solution
Using transform
for example, you can create a new column like this:
obj <- merge(foo, footoo, all = FALSE)
transform(obj, newfoo = foo/footoo )
OTHER TIPS
You can safely do as below. xts
will always cbind
or merge
by time index.
mergedXTS <- merge(foo, footoo, all=FALSE)
mergedXTS$newfoo <- mergedXTS$foo/mergedXTS$footoo