[R] Data frame self-join with no duplicates

Xin Zhang xin.zhang at gmail.com
Mon Sep 27 13:29:53 CEST 2010


Suppose I have the following data frame (df):

Year    Price
-------------------
2001    10
2002    20
2003    30

I would like to produce another data frame like this:

a.Year    a.Price    b.Year    b.Price
----------------------------------------------------
2002    20    2001    10
2003    30    2001    10
2003    30    2002    20

In SQL, this can be done as

select a.*, b.*
from df as a, df as b
where a.Year > b.Year

How do I do this efficiently in R?

Many thanks.



More information about the R-help mailing list