通过将行的名称与R中的另一个表进行比较,从表中选择行

时间:2018-05-30 17:28:23

标签: r

我有2个表(从read.table导入),比方说GDP和Pop。每个第一列都有日期。每个表都有不同的维度(行)。

这里输出Pop

> dput(head(cnp16ov))
structure(list(DATE = structure(1:6, .Label = c("1948-01-01", 
"1948-02-01", "1948-03-01", "1948-04-01", "1948-05-01", "1948-06-01", 
"1948-07-01", "1948-08-01", "1948-09-01", "1948-10-01", "1948-11-01", 
"1948-12-01", "1949-01-01", "1949-02-01", "1949-03-01", "1949-04-01", 
"1949-05-01", "1949-06-01", "1949-07-01", "1949-08-01", "1949-09-01", 
"1949-10-01", "1949-11-01", "1949-12-01", "1950-01-01", "1950-02-01", 
"1950-03-01", "1950-04-01", "1950-05-01", "1950-06-01", "1950-07-01", 
"1950-08-01", "1950-09-01", "1950-10-01", "1950-11-01", "1950-12-01", 
"1951-01-01", "1951-02-01", "1951-03-01", "1951-04-01", "1951-05-01", 
"1951-06-01", "1951-07-01", "1951-08-01", "1951-09-01", "1951-10-01", 
"1951-11-01", "1951-12-01", "1952-01-01", "1952-02-01", "1952-03-01", 
"1952-04-01", "1952-05-01", "1952-06-01", "1952-07-01", "1952-08-01", 
"1952-09-01", "1952-10-01", "1952-11-01", "1952-12-01", "1953-01-01", 
"1953-02-01", "1953-03-01", "1953-04-01", "1953-05-01", "1953-06-01", 
"1953-07-01", "1953-08-01", "1953-09-01", "1953-10-01", "1953-11-01", 
"1953-12-01", "1954-01-01", "1954-02-01", "1954-03-01", "1954-04-01", 
"1954-05-01", "1954-06-01", "1954-07-01", "1954-08-01", "1954-09-01", 
"1954-10-01", "1954-11-01", "1954-12-01", "1955-01-01", "1955-02-01", 
"1955-03-01", "1955-04-01", "1955-05-01", "1955-06-01", "1955-07-01", 
"1955-08-01", "1955-09-01", "1955-10-01", "1955-11-01", "1955-12-01", 
"1956-01-01", "1956-02-01", "1956-03-01", "1956-04-01", "1956-05-01", 
"1956-06-01", "1956-07-01", "1956-08-01", "1956-09-01", "1956-10-01", 
"1956-11-01", "1956-12-01", "1957-01-01", "1957-02-01", "1957-03-01", 
"1957-04-01", "1957-05-01", "1957-06-01", "1957-07-01", "1957-08-01", 
"1957-09-01", "1957-10-01", "1957-11-01", "1957-12-01", "1958-01-01", 
"1958-02-01", "1958-03-01", "1958-04-01", "1958-05-01", "1958-06-01", 
"1958-07-01", "1958-08-01", "1958-09-01", "1958-10-01", "1958-11-01", 
"1958-12-01", "1959-01-01", "1959-02-01", "1959-03-01", "1959-04-01", 
"1959-05-01", "1959-06-01", "1959-07-01", "1959-08-01", "1959-09-01", 
"1959-10-01", "1959-11-01", "1959-12-01", "1960-01-01", "1960-02-01", 
"1960-03-01", "1960-04-01", "1960-05-01", "1960-06-01", "1960-07-01", 
"1960-08-01", "1960-09-01", "1960-10-01", "1960-11-01", "1960-12-01", 
"1961-01-01", "1961-02-01", "1961-03-01", "1961-04-01", "1961-05-01", 
"1961-06-01", "1961-07-01", "1961-08-01", "1961-09-01", "1961-10-01", 
"1961-11-01", "1961-12-01", "1962-01-01", "1962-02-01", "1962-03-01", 
"1962-04-01", "1962-05-01", "1962-06-01", "1962-07-01", "1962-08-01", 
"1962-09-01", "1962-10-01", "1962-11-01", "1962-12-01", "1963-01-01", 
"1963-02-01", "1963-03-01", "1963-04-01", "1963-05-01", "1963-06-01", 
"1963-07-01", "1963-08-01", "1963-09-01", "1963-10-01", "1963-11-01", 
"1963-12-01", "1964-01-01", "1964-02-01", "1964-03-01", "1964-04-01", 
"1964-05-01", "1964-06-01", "1964-07-01", "1964-08-01", "1964-09-01", 
"1964-10-01", "1964-11-01", "1964-12-01", "1965-01-01", "1965-02-01", 
"1965-03-01", "1965-04-01", "1965-05-01", "1965-06-01", "1965-07-01", 
"1965-08-01", "1965-09-01", "1965-10-01", "1965-11-01", "1965-12-01", 
"1966-01-01", "1966-02-01", "1966-03-01", "1966-04-01", "1966-05-01", 
"1966-06-01", "1966-07-01", "1966-08-01", "1966-09-01", "1966-10-01", 
"1966-11-01", "1966-12-01", "1967-01-01", "1967-02-01", "1967-03-01", 
"1967-04-01", "1967-05-01", "1967-06-01", "1967-07-01", "1967-08-01", 
"1967-09-01", "1967-10-01", "1967-11-01", "1967-12-01", "1968-01-01", 
"1968-02-01", "1968-03-01", "1968-04-01", "1968-05-01", "1968-06-01", 
"1968-07-01", "1968-08-01", "1968-09-01", "1968-10-01", "1968-11-01", 
"1968-12-01", "1969-01-01", "1969-02-01", "1969-03-01", "1969-04-01", 
"1969-05-01", "1969-06-01", "1969-07-01", "1969-08-01", "1969-09-01", 
"1969-10-01", "1969-11-01", "1969-12-01", "1970-01-01", "1970-02-01", 
"1970-03-01", "1970-04-01", "1970-05-01", "1970-06-01", "1970-07-01", 
"1970-08-01", "1970-09-01", "1970-10-01", "1970-11-01", "1970-12-01", 
"1971-01-01", "1971-02-01", "1971-03-01", "1971-04-01", "1971-05-01", 
"1971-06-01", "1971-07-01", "1971-08-01", "1971-09-01", "1971-10-01", 
"1971-11-01", "1971-12-01", "1972-01-01", "1972-02-01", "1972-03-01", 
"1972-04-01", "1972-05-01", "1972-06-01", "1972-07-01", "1972-08-01", 
"1972-09-01", "1972-10-01", "1972-11-01", "1972-12-01", "1973-01-01", 
"1973-02-01", "1973-03-01", "1973-04-01", "1973-05-01", "1973-06-01", 
"1973-07-01", "1973-08-01", "1973-09-01", "1973-10-01", "1973-11-01", 
"1973-12-01", "1974-01-01", "1974-02-01", "1974-03-01", "1974-04-01", 
"1974-05-01", "1974-06-01", "1974-07-01", "1974-08-01", "1974-09-01", 
"1974-10-01", "1974-11-01", "1974-12-01", "1975-01-01", "1975-02-01", 
"1975-03-01", "1975-04-01", "1975-05-01", "1975-06-01", "1975-07-01", 
"1975-08-01", "1975-09-01", "1975-10-01", "1975-11-01", "1975-12-01", 
"1976-01-01", "1976-02-01", "1976-03-01", "1976-04-01", "1976-05-01", 
"1976-06-01", "1976-07-01", "1976-08-01", "1976-09-01", "1976-10-01", 
"1976-11-01", "1976-12-01", "1977-01-01", "1977-02-01", "1977-03-01", 
"1977-04-01", "1977-05-01", "1977-06-01", "1977-07-01", "1977-08-01", 
"1977-09-01", "1977-10-01", "1977-11-01", "1977-12-01", "1978-01-01", 
"1978-02-01", "1978-03-01", "1978-04-01", "1978-05-01", "1978-06-01", 
"1978-07-01", "1978-08-01", "1978-09-01", "1978-10-01", "1978-11-01", 
"1978-12-01", "1979-01-01", "1979-02-01", "1979-03-01", "1979-04-01", 
"1979-05-01", "1979-06-01", "1979-07-01", "1979-08-01", "1979-09-01", 
"1979-10-01", "1979-11-01", "1979-12-01", "1980-01-01", "1980-02-01", 
"1980-03-01", "1980-04-01", "1980-05-01", "1980-06-01", "1980-07-01", 
"1980-08-01", "1980-09-01", "1980-10-01", "1980-11-01", "1980-12-01", 
"1981-01-01", "1981-02-01", "1981-03-01", "1981-04-01", "1981-05-01", 
"1981-06-01", "1981-07-01", "1981-08-01", "1981-09-01", "1981-10-01", 
"1981-11-01", "1981-12-01", "1982-01-01", "1982-02-01", "1982-03-01", 
"1982-04-01", "1982-05-01", "1982-06-01", "1982-07-01", "1982-08-01", 
"1982-09-01", "1982-10-01", "1982-11-01", "1982-12-01", "1983-01-01", 
"1983-02-01", "1983-03-01", "1983-04-01", "1983-05-01", "1983-06-01", 
"1983-07-01", "1983-08-01", "1983-09-01", "1983-10-01", "1983-11-01", 
"1983-12-01", "1984-01-01", "1984-02-01", "1984-03-01", "1984-04-01", 
"1984-05-01", "1984-06-01", "1984-07-01", "1984-08-01", "1984-09-01", 
"1984-10-01", "1984-11-01", "1984-12-01", "1985-01-01", "1985-02-01", 
"1985-03-01", "1985-04-01", "1985-05-01", "1985-06-01", "1985-07-01", 
"1985-08-01", "1985-09-01", "1985-10-01", "1985-11-01", "1985-12-01", 
"1986-01-01", "1986-02-01", "1986-03-01", "1986-04-01", "1986-05-01", 
"1986-06-01", "1986-07-01", "1986-08-01", "1986-09-01", "1986-10-01", 
"1986-11-01", "1986-12-01", "1987-01-01", "1987-02-01", "1987-03-01", 
"1987-04-01", "1987-05-01", "1987-06-01", "1987-07-01", "1987-08-01", 
"1987-09-01", "1987-10-01", "1987-11-01", "1987-12-01", "1988-01-01", 
"1988-02-01", "1988-03-01", "1988-04-01", "1988-05-01", "1988-06-01", 
"1988-07-01", "1988-08-01", "1988-09-01", "1988-10-01", "1988-11-01", 
"1988-12-01", "1989-01-01", "1989-02-01", "1989-03-01", "1989-04-01", 
"1989-05-01", "1989-06-01", "1989-07-01", "1989-08-01", "1989-09-01", 
"1989-10-01", "1989-11-01", "1989-12-01", "1990-01-01", "1990-02-01", 
"1990-03-01", "1990-04-01", "1990-05-01", "1990-06-01", "1990-07-01", 
"1990-08-01", "1990-09-01", "1990-10-01", "1990-11-01", "1990-12-01", 
"1991-01-01", "1991-02-01", "1991-03-01", "1991-04-01", "1991-05-01", 
"1991-06-01", "1991-07-01", "1991-08-01", "1991-09-01", "1991-10-01", 
"1991-11-01", "1991-12-01", "1992-01-01", "1992-02-01", "1992-03-01", 
"1992-04-01", "1992-05-01", "1992-06-01", "1992-07-01", "1992-08-01", 
"1992-09-01", "1992-10-01", "1992-11-01", "1992-12-01", "1993-01-01", 
"1993-02-01", "1993-03-01", "1993-04-01", "1993-05-01", "1993-06-01", 
"1993-07-01", "1993-08-01", "1993-09-01", "1993-10-01", "1993-11-01", 
"1993-12-01", "1994-01-01", "1994-02-01", "1994-03-01", "1994-04-01", 
"1994-05-01", "1994-06-01", "1994-07-01", "1994-08-01", "1994-09-01", 
"1994-10-01", "1994-11-01", "1994-12-01", "1995-01-01", "1995-02-01", 
"1995-03-01", "1995-04-01", "1995-05-01", "1995-06-01", "1995-07-01", 
"1995-08-01", "1995-09-01", "1995-10-01", "1995-11-01", "1995-12-01", 
"1996-01-01", "1996-02-01", "1996-03-01", "1996-04-01", "1996-05-01", 
"1996-06-01", "1996-07-01", "1996-08-01", "1996-09-01", "1996-10-01", 
"1996-11-01", "1996-12-01", "1997-01-01", "1997-02-01", "1997-03-01", 
"1997-04-01", "1997-05-01", "1997-06-01", "1997-07-01", "1997-08-01", 
"1997-09-01", "1997-10-01", "1997-11-01", "1997-12-01", "1998-01-01", 
"1998-02-01", "1998-03-01", "1998-04-01", "1998-05-01", "1998-06-01", 
"1998-07-01", "1998-08-01", "1998-09-01", "1998-10-01", "1998-11-01", 
"1998-12-01", "1999-01-01", "1999-02-01", "1999-03-01", "1999-04-01", 
"1999-05-01", "1999-06-01", "1999-07-01", "1999-08-01", "1999-09-01", 
"1999-10-01", "1999-11-01", "1999-12-01", "2000-01-01", "2000-02-01", 
"2000-03-01", "2000-04-01", "2000-05-01", "2000-06-01", "2000-07-01", 
"2000-08-01", "2000-09-01", "2000-10-01", "2000-11-01", "2000-12-01", 
"2001-01-01", "2001-02-01", "2001-03-01", "2001-04-01", "2001-05-01", 
"2001-06-01", "2001-07-01", "2001-08-01", "2001-09-01", "2001-10-01", 
"2001-11-01", "2001-12-01", "2002-01-01", "2002-02-01", "2002-03-01", 
"2002-04-01", "2002-05-01", "2002-06-01", "2002-07-01", "2002-08-01", 
"2002-09-01", "2002-10-01", "2002-11-01", "2002-12-01", "2003-01-01", 
"2003-02-01", "2003-03-01", "2003-04-01", "2003-05-01", "2003-06-01", 
"2003-07-01", "2003-08-01", "2003-09-01", "2003-10-01", "2003-11-01", 
"2003-12-01", "2004-01-01", "2004-02-01", "2004-03-01", "2004-04-01", 
"2004-05-01", "2004-06-01", "2004-07-01", "2004-08-01", "2004-09-01", 
"2004-10-01", "2004-11-01", "2004-12-01", "2005-01-01", "2005-02-01", 
"2005-03-01", "2005-04-01", "2005-05-01", "2005-06-01", "2005-07-01", 
"2005-08-01", "2005-09-01", "2005-10-01", "2005-11-01", "2005-12-01", 
"2006-01-01", "2006-02-01", "2006-03-01", "2006-04-01", "2006-05-01", 
"2006-06-01", "2006-07-01", "2006-08-01", "2006-09-01", "2006-10-01", 
"2006-11-01", "2006-12-01", "2007-01-01", "2007-02-01", "2007-03-01", 
"2007-04-01", "2007-05-01", "2007-06-01", "2007-07-01", "2007-08-01", 
"2007-09-01", "2007-10-01", "2007-11-01", "2007-12-01", "2008-01-01", 
"2008-02-01", "2008-03-01", "2008-04-01", "2008-05-01", "2008-06-01", 
"2008-07-01", "2008-08-01", "2008-09-01", "2008-10-01", "2008-11-01", 
"2008-12-01", "2009-01-01", "2009-02-01", "2009-03-01", "2009-04-01", 
"2009-05-01", "2009-06-01", "2009-07-01", "2009-08-01", "2009-09-01", 
"2009-10-01", "2009-11-01", "2009-12-01", "2010-01-01", "2010-02-01", 
"2010-03-01", "2010-04-01", "2010-05-01", "2010-06-01", "2010-07-01", 
"2010-08-01", "2010-09-01", "2010-10-01", "2010-11-01", "2010-12-01", 
"2011-01-01", "2011-02-01", "2011-03-01", "2011-04-01", "2011-05-01", 
"2011-06-01", "2011-07-01", "2011-08-01", "2011-09-01", "2011-10-01", 
"2011-11-01", "2011-12-01", "2012-01-01", "2012-02-01", "2012-03-01", 
"2012-04-01", "2012-05-01", "2012-06-01", "2012-07-01", "2012-08-01", 
"2012-09-01", "2012-10-01", "2012-11-01", "2012-12-01", "2013-01-01", 
"2013-02-01", "2013-03-01", "2013-04-01", "2013-05-01", "2013-06-01", 
"2013-07-01", "2013-08-01", "2013-09-01", "2013-10-01", "2013-11-01", 
"2013-12-01", "2014-01-01", "2014-02-01", "2014-03-01", "2014-04-01", 
"2014-05-01", "2014-06-01", "2014-07-01", "2014-08-01", "2014-09-01", 
"2014-10-01", "2014-11-01", "2014-12-01", "2015-01-01", "2015-02-01", 
"2015-03-01", "2015-04-01", "2015-05-01", "2015-06-01", "2015-07-01", 
"2015-08-01", "2015-09-01", "2015-10-01", "2015-11-01", "2015-12-01", 
"2016-01-01", "2016-02-01", "2016-03-01", "2016-04-01", "2016-05-01", 
"2016-06-01", "2016-07-01", "2016-08-01", "2016-09-01", "2016-10-01", 
"2016-11-01", "2016-12-01", "2017-01-01", "2017-02-01", "2017-03-01", 
"2017-04-01", "2017-05-01", "2017-06-01", "2017-07-01", "2017-08-01", 
"2017-09-01", "2017-10-01", "2017-11-01", "2017-12-01", "2018-01-01", 
"2018-02-01", "2018-03-01", "2018-04-01"), class = "factor"), 
    CNP16OV = c(102603L, 102698L, 102771L, 102831L, 102923L, 
    102992L)), .Names = c("DATE", "CNP16OV"), row.names = c(NA, 
6L), class = "data.frame")

这是GDP的原因

> dput(head(gdpc1))
structure(list(DATE = structure(1:6, .Label = c("1947-01-01", 
"1947-04-01", "1947-07-01", "1947-10-01", "1948-01-01", "1948-04-01", 
"1948-07-01", "1948-10-01", "1949-01-01", "1949-04-01", "1949-07-01", 
"1949-10-01", "1950-01-01", "1950-04-01", "1950-07-01", "1950-10-01", 
"1951-01-01", "1951-04-01", "1951-07-01", "1951-10-01", "1952-01-01", 
"1952-04-01", "1952-07-01", "1952-10-01", "1953-01-01", "1953-04-01", 
"1953-07-01", "1953-10-01", "1954-01-01", "1954-04-01", "1954-07-01", 
"1954-10-01", "1955-01-01", "1955-04-01", "1955-07-01", "1955-10-01", 
"1956-01-01", "1956-04-01", "1956-07-01", "1956-10-01", "1957-01-01", 
"1957-04-01", "1957-07-01", "1957-10-01", "1958-01-01", "1958-04-01", 
"1958-07-01", "1958-10-01", "1959-01-01", "1959-04-01", "1959-07-01", 
"1959-10-01", "1960-01-01", "1960-04-01", "1960-07-01", "1960-10-01", 
"1961-01-01", "1961-04-01", "1961-07-01", "1961-10-01", "1962-01-01", 
"1962-04-01", "1962-07-01", "1962-10-01", "1963-01-01", "1963-04-01", 
"1963-07-01", "1963-10-01", "1964-01-01", "1964-04-01", "1964-07-01", 
"1964-10-01", "1965-01-01", "1965-04-01", "1965-07-01", "1965-10-01", 
"1966-01-01", "1966-04-01", "1966-07-01", "1966-10-01", "1967-01-01", 
"1967-04-01", "1967-07-01", "1967-10-01", "1968-01-01", "1968-04-01", 
"1968-07-01", "1968-10-01", "1969-01-01", "1969-04-01", "1969-07-01", 
"1969-10-01", "1970-01-01", "1970-04-01", "1970-07-01", "1970-10-01", 
"1971-01-01", "1971-04-01", "1971-07-01", "1971-10-01", "1972-01-01", 
"1972-04-01", "1972-07-01", "1972-10-01", "1973-01-01", "1973-04-01", 
"1973-07-01", "1973-10-01", "1974-01-01", "1974-04-01", "1974-07-01", 
"1974-10-01", "1975-01-01", "1975-04-01", "1975-07-01", "1975-10-01", 
"1976-01-01", "1976-04-01", "1976-07-01", "1976-10-01", "1977-01-01", 
"1977-04-01", "1977-07-01", "1977-10-01", "1978-01-01", "1978-04-01", 
"1978-07-01", "1978-10-01", "1979-01-01", "1979-04-01", "1979-07-01", 
"1979-10-01", "1980-01-01", "1980-04-01", "1980-07-01", "1980-10-01", 
"1981-01-01", "1981-04-01", "1981-07-01", "1981-10-01", "1982-01-01", 
"1982-04-01", "1982-07-01", "1982-10-01", "1983-01-01", "1983-04-01", 
"1983-07-01", "1983-10-01", "1984-01-01", "1984-04-01", "1984-07-01", 
"1984-10-01", "1985-01-01", "1985-04-01", "1985-07-01", "1985-10-01", 
"1986-01-01", "1986-04-01", "1986-07-01", "1986-10-01", "1987-01-01", 
"1987-04-01", "1987-07-01", "1987-10-01", "1988-01-01", "1988-04-01", 
"1988-07-01", "1988-10-01", "1989-01-01", "1989-04-01", "1989-07-01", 
"1989-10-01", "1990-01-01", "1990-04-01", "1990-07-01", "1990-10-01", 
"1991-01-01", "1991-04-01", "1991-07-01", "1991-10-01", "1992-01-01", 
"1992-04-01", "1992-07-01", "1992-10-01", "1993-01-01", "1993-04-01", 
"1993-07-01", "1993-10-01", "1994-01-01", "1994-04-01", "1994-07-01", 
"1994-10-01", "1995-01-01", "1995-04-01", "1995-07-01", "1995-10-01", 
"1996-01-01", "1996-04-01", "1996-07-01", "1996-10-01", "1997-01-01", 
"1997-04-01", "1997-07-01", "1997-10-01", "1998-01-01", "1998-04-01", 
"1998-07-01", "1998-10-01", "1999-01-01", "1999-04-01", "1999-07-01", 
"1999-10-01", "2000-01-01", "2000-04-01", "2000-07-01", "2000-10-01", 
"2001-01-01", "2001-04-01", "2001-07-01", "2001-10-01", "2002-01-01", 
"2002-04-01", "2002-07-01", "2002-10-01", "2003-01-01", "2003-04-01", 
"2003-07-01", "2003-10-01", "2004-01-01", "2004-04-01", "2004-07-01", 
"2004-10-01", "2005-01-01", "2005-04-01", "2005-07-01", "2005-10-01", 
"2006-01-01", "2006-04-01", "2006-07-01", "2006-10-01", "2007-01-01", 
"2007-04-01", "2007-07-01", "2007-10-01", "2008-01-01", "2008-04-01", 
"2008-07-01", "2008-10-01", "2009-01-01", "2009-04-01", "2009-07-01", 
"2009-10-01", "2010-01-01", "2010-04-01", "2010-07-01", "2010-10-01", 
"2011-01-01", "2011-04-01", "2011-07-01", "2011-10-01", "2012-01-01", 
"2012-04-01", "2012-07-01", "2012-10-01", "2013-01-01", "2013-04-01", 
"2013-07-01", "2013-10-01", "2014-01-01", "2014-04-01", "2014-07-01", 
"2014-10-01", "2015-01-01", "2015-04-01", "2015-07-01", "2015-10-01", 
"2016-01-01", "2016-04-01", "2016-07-01", "2016-10-01", "2017-01-01", 
"2017-04-01", "2017-07-01", "2017-10-01", "2018-01-01"), class = "factor"), 
    GDPC1 = c(1934.471, 1932.281, 1930.315, 1960.705, 1989.535, 
    2021.851)), .Names = c("DATE", "GDPC1"), row.names = c(NA, 
6L), class = "data.frame")

我想选择具有相同日期GDP的Pop行。

我试过

Pop<-Pop[Pop$DATE==GDP$DATE]

但是我收到以下错误:

Error in Ops.factor(Pop$DATE, GDP$DATE) : 
  level sets of factors are different
In addition: Warning message:
In is.na(e1) | is.na(e2) :
  longer object length is not a multiple of shorter object length

我认为问题是行被认为是一个级别,因为我们有不同的级别,我们无法比较两个表。

2 个答案:

答案 0 :(得分:1)

我认为问题可能在于变量的类型,即factor。 因此转换为char可以解决此问题

Pop <- Pop[as.character(Pop$DATE)==as.character(GDP$DATE),]

请记住data.frame()可以像df['rows', 'columns']一样访问,因此您需要使用该逗号来识别您正在处理的行。

答案 1 :(得分:1)

从Biro的回答中,我得到了一个有效的答案。我们应该使用%in%运算符,而不是==。

as.character(pop$DATE)%in%as.character(gdp$DATE)

我们需要小心这个算子,因为它不对称,即用RHS改变LHS会给出不同的向量。