An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120123/2b718e05/attachment.pl>
How do I intersecttwo time series?
15 messages · Michael, Brian G. Peterson, Jeff Ryan +3 more
On Mon, 2012-01-23 at 08:06 -0600, Michael wrote:
I have two xts objects...and they have coulmns with the same names.ie their column represent the same variables. The only difference is that the values in the rows may be different. At precisely the same timestamps the observations can be exactly the same. How do I find the intersection of these two time series ie the rows where the observations are identical including the time stamps? How do I find intersection where a few specified coulmns are identical including the time stamps? Thanks a lot!
?merge ?ifelse merge is amply covered in the xts documentation, and ifelse is covered in many write-ups on vectorized operations in R.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120123/13b765ba/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120123/ac7a8a83/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120123/15072dd1/attachment.pl>
I will repeat my earlier advice: ?merge
On Mon, 2012-01-23 at 17:53 -0600, Michael wrote:
Oh I forgot one thing: xts_one and xts_two are not neccessarily the same length... In effect, I was looking for a time series set-operation "intersect".... Thank you! On Mon, Jan 23, 2012 at 12:35 PM, Jun Zhu <junzhu98 at yahoo.com> wrote:
Assume you are testing the first column l_result <- ifelse(l_xts_one[,1] == l_xts_two[,1], l_xts_one[,1],NA) --- On *Mon, 1/23/12, Brian G. Peterson <brian at braverock.com>* wrote: From: Brian G. Peterson <brian at braverock.com> Subject: Re: [R-SIG-Finance] How do I intersecttwo time series? To: "Michael" <comtech.usa at gmail.com> Cc: "r-sig-finance" <r-sig-finance at stat.math.ethz.ch> Date: Monday, January 23, 2012, 8:25 AM On Mon, 2012-01-23 at 08:06 -0600, Michael wrote:
I have two xts objects...and they have coulmns with the same names.ie their column represent the same variables. The only difference is that the values in the rows may be different. At precisely the same timestamps the observations can be exactly the same. How do I find the intersection of these two time series ie the rows where the observations are identical including the time stamps? How do I find intersection where a few specified coulmns are identical including the time stamps? Thanks a lot!
?merge ?ifelse merge is amply covered in the xts documentation, and ifelse is covered in many write-ups on vectorized operations in R.
_______________________________________________ R-SIG-Finance at r-project.org<http://mc/compose?to=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.
[[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.
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120123/7dff6b6d/attachment.pl>
On Mon, 2012-01-23 at 18:58 -0600, Michael wrote:
Yes, but merge creates a bunch of "NA"s ... and we are not merging but doing "intersections"? I cannot seem to find a way to use "merge" to do "intersections"... I have searched/googled numerous times... Maybe there is something I am missing and a trick?
Those NA's exist because one series has a timestamp and the other doesn't. Normally, that's what you want. na.omit(merge(x,y))
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
Try: ?merge.xts You want join="inner" if I have been following this. Jeff Jeffrey Ryan | Founder | jeffrey.ryan at lemnica.com www.lemnica.com
On Jan 23, 2012, at 7:02 PM, "Brian G. Peterson" <brian at braverock.com> wrote:
On Mon, 2012-01-23 at 18:58 -0600, Michael wrote:
Yes, but merge creates a bunch of "NA"s ... and we are not merging but doing "intersections"? I cannot seem to find a way to use "merge" to do "intersections"... I have searched/googled numerous times... Maybe there is something I am missing and a trick?
Those NA's exist because one series has a timestamp and the other doesn't. Normally, that's what you want. na.omit(merge(x,y)) -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
_______________________________________________ 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120123/8223d228/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120123/1a9192e2/attachment.pl>
Michael, Maybe you do not realize that when someone writes a word with a question mark in front of it, it means that you should look at the help page for that function. ?For example, if you type "?merge" in an R terminal (without the quotes) it will open the help page for that function. ?Another option is to type help(merge) Hope this makes it easier for you to find answers in the future, Garrett
On Mon, Jan 23, 2012 at 5:53 PM, Michael <comtech.usa at gmail.com> wrote:
Oh I forgot one thing: xts_one and xts_two are not neccessarily the same length... In effect, I was looking for a time series set-operation "intersect".... Thank you! On Mon, Jan 23, 2012 at 12:35 PM, Jun Zhu <junzhu98 at yahoo.com> wrote:
? Assume you are testing the first column l_result <- ifelse(l_xts_one[,1] == l_xts_two[,1], l_xts_one[,1],NA) --- On *Mon, 1/23/12, Brian G. Peterson <brian at braverock.com>* wrote: From: Brian G. Peterson <brian at braverock.com> Subject: Re: [R-SIG-Finance] How do I intersecttwo time series? To: "Michael" <comtech.usa at gmail.com> Cc: "r-sig-finance" <r-sig-finance at stat.math.ethz.ch> Date: Monday, January 23, 2012, 8:25 AM ? On Mon, 2012-01-23 at 08:06 -0600, Michael wrote:
I have two xts objects...and they have coulmns with the same names.ie their column represent the same variables. The only difference is that the values in the rows may be different. At precisely the same timestamps the observations can be exactly the same. How do I find the intersection of these two time series ie the rows where the observations are identical including the time stamps? How do I find intersection where a few specified coulmns are identical including the time stamps? Thanks a lot!
?merge ?ifelse merge is amply covered in the xts documentation, and ifelse is covered in many write-ups on vectorized operations in R.
_______________________________________________ R-SIG-Finance at r-project.org<http://mc/compose?to=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.
? ? ? ?[[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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120124/952ceb51/attachment.pl>
Well, it was just a guess since it seemed as if you didn't try it. Maybe next time you could show us what you tried and why it didn't do what you wanted. Then, provide a sample dataset and desired outcome. Those types of questions are much easier for us to answer, which is why it is suggested here: http://www.r-project.org/posting-guide.html Thanks for your understanding, Garrett
On Tue, Jan 24, 2012 at 8:55 AM, Michael <comtech.usa at gmail.com> wrote:
Hi G See, Thanks but I have been watching "?merge" hundreds of times... It's very terse and there are lots of hidden tricks... Thanks a lot any way! And thanks a lot for all the help folks! On Tue, Jan 24, 2012 at 2:53 AM, G See <gsee000 at gmail.com> wrote:
Michael, Maybe you do not realize that when someone writes a word with a question mark in front of it, it means that you should look at the help page for that function. ?For example, if you type "?merge" in an R terminal (without the quotes) it will open the help page for that function. ?Another option is to type help(merge) Hope this makes it easier for you to find answers in the future, Garrett On Mon, Jan 23, 2012 at 5:53 PM, Michael <comtech.usa at gmail.com> wrote:
Oh I forgot one thing: xts_one and xts_two are not neccessarily the same length... In effect, I was looking for a time series set-operation "intersect".... Thank you! On Mon, Jan 23, 2012 at 12:35 PM, Jun Zhu <junzhu98 at yahoo.com> wrote:
? Assume you are testing the first column l_result <- ifelse(l_xts_one[,1] == l_xts_two[,1], l_xts_one[,1],NA) --- On *Mon, 1/23/12, Brian G. Peterson <brian at braverock.com>* wrote: From: Brian G. Peterson <brian at braverock.com> Subject: Re: [R-SIG-Finance] How do I intersecttwo time series? To: "Michael" <comtech.usa at gmail.com> Cc: "r-sig-finance" <r-sig-finance at stat.math.ethz.ch> Date: Monday, January 23, 2012, 8:25 AM ? On Mon, 2012-01-23 at 08:06 -0600, Michael wrote:
I have two xts objects...and they have coulmns with the same names.ie their column represent the same variables. The only difference is that the values in the rows may be different. At precisely the same timestamps the observations can be exactly the same. How do I find the intersection of these two time series ie the rows where the observations are identical including the time stamps? How do I find intersection where a few specified coulmns are identical including the time stamps? Thanks a lot!
?merge ?ifelse merge is amply covered in the xts documentation, and ifelse is covered in many write-ups on vectorized operations in R.
_______________________________________________ R-SIG-Finance at r-project.org<http://mc/compose?to=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.
? ? ? ?[[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.
The OP's confusion might also stem from the fact that ?merge doesn't actually lead to ?merge.xts which would have been much more helpful here. I think it's a suboptimal consequence of method dispatch that there are no pointers to documented methods...I'll try to work up a small patch to `?` and put it on Rd to see if it gets any traction. Perhaps something like
?merge # pops up merge's help page, but also cat()s
There are documented methods for: merge.xts merge.dendrogram merge.zoo You may wish to check these as well. Or something like that. Feel free to send me thoughts off-list Michael
On Tue, Jan 24, 2012 at 10:10 AM, G See <gsee000 at gmail.com> wrote:
Well, it was just a guess since it seemed as if you didn't try it. Maybe next time you could show us what you tried and why it didn't do what you wanted. ?Then, provide a sample dataset and desired outcome. Those types of questions are much easier for us to answer, which is why it is suggested here: http://www.r-project.org/posting-guide.html Thanks for your understanding, Garrett On Tue, Jan 24, 2012 at 8:55 AM, Michael <comtech.usa at gmail.com> wrote:
Hi G See, Thanks but I have been watching "?merge" hundreds of times... It's very terse and there are lots of hidden tricks... Thanks a lot any way! And thanks a lot for all the help folks! On Tue, Jan 24, 2012 at 2:53 AM, G See <gsee000 at gmail.com> wrote:
Michael, Maybe you do not realize that when someone writes a word with a question mark in front of it, it means that you should look at the help page for that function. ?For example, if you type "?merge" in an R terminal (without the quotes) it will open the help page for that function. ?Another option is to type help(merge) Hope this makes it easier for you to find answers in the future, Garrett On Mon, Jan 23, 2012 at 5:53 PM, Michael <comtech.usa at gmail.com> wrote:
Oh I forgot one thing: xts_one and xts_two are not neccessarily the same length... In effect, I was looking for a time series set-operation "intersect".... Thank you! On Mon, Jan 23, 2012 at 12:35 PM, Jun Zhu <junzhu98 at yahoo.com> wrote:
? Assume you are testing the first column l_result <- ifelse(l_xts_one[,1] == l_xts_two[,1], l_xts_one[,1],NA) --- On *Mon, 1/23/12, Brian G. Peterson <brian at braverock.com>* wrote: From: Brian G. Peterson <brian at braverock.com> Subject: Re: [R-SIG-Finance] How do I intersecttwo time series? To: "Michael" <comtech.usa at gmail.com> Cc: "r-sig-finance" <r-sig-finance at stat.math.ethz.ch> Date: Monday, January 23, 2012, 8:25 AM ? On Mon, 2012-01-23 at 08:06 -0600, Michael wrote:
I have two xts objects...and they have coulmns with the same names.ie their column represent the same variables. The only difference is that the values in the rows may be different. At precisely the same timestamps the observations can be exactly the same. How do I find the intersection of these two time series ie the rows where the observations are identical including the time stamps? How do I find intersection where a few specified coulmns are identical including the time stamps? Thanks a lot!
?merge ?ifelse merge is amply covered in the xts documentation, and ifelse is covered in many write-ups on vectorized operations in R.
_______________________________________________ R-SIG-Finance at r-project.org<http://mc/compose?to=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.
? ? ? ?[[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.
_______________________________________________ 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.