合并功能产生随机NA

时间:2019-03-28 02:30:12

标签: r

我正在尝试在DATE合并两个数据集,但是即使两个单独数据集中所有日期的值都存在,NA仍会在我的新数据集中形成。

此外,该顺序还需要正确的顺序(即:日期:2000-1、2000-2、2000-3、2000-12)。我该如何解决订单问题,而不是读2000-1、2000-12、2000-2 ...,将不胜感激。

tq <-read.table(header=T, sep=",",text="
DATE, avalanches
2000-1,1
2000-2,0
2000-3,0
2000-12,0
2001-1,0
2001-2,1
2001-3,0
2001-12,0
2002-1,0
2002-2,0
2002-3,1
2002-12,0
2003-1,0
2003-2,1
2003-3,0
2003-12,0
2004-1,0
2004-2,1
2004-3,0
2004-12,2
2005-1,1
2005-2,0
2005-3,0
2005-12,1
2006-1,0
2006-2,0
2006-3,0
2006-12,1
2007-1,0
2007-2,2
2007-3,0
2007-12,3
2008-1,0
2008-2,0
2008-3,0
2008-12,4
2009-1,0
2009-2,0
2009-3,0
2009-12,39
2010-1,81
2010-2,143
2010-3,39
2010-12,49
2011-1,25
2011-2,39
2011-3,57
2011-12,17
2012-1,92
2012-2,37
2012-3,55
2012-12,141
2013-1,136
2013-2,97
2013-3,122
2013-12,155
2014-1,125
2014-2,155
2014-3,100
2014-12,129
2015-1,107
2015-2,62
2015-3,94
2015-12,150
2016-1,195
2016-2,96
2016-3,96
2016-12,131
2017-1,201
2017-2,154
2017-3,93
2017-12,116
2018-1,168
2018-2,118
2018-3,126
2018-12,166
2019-1,173
2019-2,176
2019-3,162")




avalancheobs<-read.csv(header=T, stringsAsFactors =F, text='
STATION,NAME,DATE,DT32,SNOW,TMIN
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT","2000-01","20","15.0","27.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-02","16","5.1","31.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-03","17","6.2","32.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-04","1","0.0","42.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-05","0","0.5","49.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-06","0","0.0","58.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-07","0","0.0","66.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-08","0","0.0","66.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-09","0","0.0","52.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-10","0","0.0","42.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-11","28","17.0","24.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2000-12","30","12.9","22.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-01","31","6.6","21.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-02","23","13.1","26.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-03","12","5.3","35.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-04","5","9.9","40.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-05","0","0.0","50.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-06","0","0.0","57.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-07","0","0.0","66.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-08","0","0.0","65.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-09","0","0.0","56.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-10","3","0.0","42.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-11","12","18.8","33.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2001-12","29","20.0","19.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-01","30","16.1","17.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-02","27","0.7","18.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-03","17","14.4","28.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-04","4","3.6","40.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-05","1","0.0","46.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-06","0","0.0","57.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-07","0","0.0","67.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-08","0","0.0","61.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-09","0","0.0","54.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-10","4","0.0","38.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-11","25","0.2","27.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2002-12","27","3.4","27.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-01","23","0.0","28.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-02","21","9.0","26.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-03","12","5.4","34.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-04","5","4.4","40.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-05","0","0.0","49.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-06","0","0.0","58.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-07","0","0.0","69.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-08","0","0.0","67.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-09","0","0.0","52.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-10","3","1.0","44.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-11","16","10.7","30.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2003-12","28","31.2","26.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-01","30","9.9","16.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-02","28","19.8","19.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-03","11","3.9","37.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-04","1","1.0","42.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-05","0","0.0","48.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-06","0","0.0","57.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-07","0","0.0","65.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-08","0","0.0","61.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-09","0","0.0","52.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-10","1","0.1","44.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-11","19","3.3","30.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2004-12","25","3.7","25.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-01","26","6.7","28.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-02","25","11.3","26.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-03","11","2.8","33.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-04","2","0.0","39.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-05","0","0.0","47.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-06","0","0.0","54.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-07","0","0.0","66.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-08","0","0.0","63.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-09","0","0.0","52.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-10","0","0.0","43.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-11","19","1.1","32.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2005-12","28","6.9","22.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-01","27","9.3","26.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-02","22","13.5","23.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-03","16","13.3","32.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-04","4","2.2","42.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-05","0","0.0","50.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-06","0","0.0","58.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-07","0","0.0","69.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-08","0","0.0","63.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-09","0","0.0","50.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-10","6","0.0","39.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-11","20","8.1","30.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2006-12","27","9.9","22.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-01","31","10.8","11.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-02","22","13.1","27.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-03","7","2.5","35.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-04","2","0.0","41.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-05","0","0.0","49.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-06","0","0.0","58.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-07","0","0.0","70.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-08","0","0.0","67.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-09","0","0.0","53.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-10","1","0.1","40.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-11","19","0.8","30.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2007-12","29","29.8","20.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-01","31","17.1","15.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-02","27","17.4","24.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-03","18","8.3","30.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-04","12","0.0","34.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-05","2","0.0","45.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-06","0","0.0","56.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-07","0","0.0","67.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-08","0","0.0","63.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-09","0","0.0","53.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-10","5","0.5","41.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-11","16","3.0","33.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2008-12","28","20.8","21.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-01","28","10.3","23.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-02","23","6.3","27.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-03","20","6.0","31.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-04","5","1.4","38.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-05","0","0.0","49.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-06","0","0.0","54.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-07","0","0.0","65.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-08","0","0.0","61.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-09","0","0.0","57.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-10","4","0.5","39.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-11","18","2.8","30.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2009-12","30","17.1","16.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-01","27","2.3","21.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-02","22","2.3","28.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-03","19","5.7","32.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-04","7","5.6","38.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-05","2","0.2","42.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-06","0","0.0","55.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-07","0","0.0","65.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-08","0","0.0","62.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-09","0","0.0","53.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-10","2","1.8","45.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-11","15","20.9","30.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2010-12","24","11.5","27.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-01","30","5.9","20.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-02","24","11.0","25.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-03","11","9.1","34.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-04","8","8.2","36.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-05","1","0.0","42.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-06","0","0.0","53.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-07","0","0.0","66.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-08","0","0.0","65.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-09","0","0.0","56.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-10","4","0.0","43.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-11","22","5.5","29.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2011-12","30","0.1","20.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-01","28","6.9","23.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-02","19","7.4","28.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-03","11","4.0","38.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-04","3","1.0","41.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-05","0","0.0","49.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-06","0","0.0","58.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-07","0","0.0","69.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-08","0","0.0","69.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-09","0","0.0","57.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-10","1","0.3","43.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-11","14","15.2","35.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2012-12","18","13.1","28.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-01","30","23.8","12.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-02","28","14.7","21.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-03","12","2.7","34.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-04","6","0.1","39.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-05","0","0.0","50.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-06","0","0.0","60.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-07","0","0.0","71.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-08","0","0.0","70.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-09","0","0.0","59.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-10","0","0.0","41.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-11","11","3.5","34.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2013-12","28","19.2","16.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-01","29","10.1","21.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-02","10","2.2","33.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-03","2","0.5","38.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-04","3","0.0","40.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-05","0","0.0","49.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-06","0","0.0","56.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-07","0","0.0","68.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-08","0","0.0","62.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-09","0","0.0","58.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-10","0","0.0","44.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-11","15","0.8","31.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2014-12","18","5.7","29.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-01","26","0.3","26.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-02","14","0.0","34.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-03","9","2.8","37.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-04","3","5.8","41.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-05","0","0.0","50.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-06","0","0.0","64.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-07","0","0.0","65.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-08","0","0.0","65.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-09","0","0.0","58.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-10","0","0.0","50.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-11","18","1.4","30.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2015-12","26","15.9","24.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-01","30","10.6","24.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-02","21","3.8","28.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-03","5","2.7","37.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-04","0","0.0","44.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-05","0","0.0","50.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-06","0","0.0","64.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-07","0","0.0","70.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-08","0","0.0","66.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-09","0","0.0","55.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-10","0","0.0","46.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-11","7","5.7","37.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2016-12","31","11.1","22.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-01","28","23.2","21.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-02","17","6.7","31.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-03","6","3.6","39.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-04","0","1.0","40.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-05","0","0.1","51.1"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-06","0","0.0","62.8"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-07","0","0.0","72.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-08","0","0.0","69.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-09","0","0.0","56.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-10","1","0.0","40.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-11","9","0.0","37.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2017-12","29","7.7","25.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-01","20","9.6","30.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-02","18","14.3","30.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-03","8","10.5","37.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-04","2","1.4","43.3"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-05","0","0.0","53.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-06","0","0.0","61.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-07","0","0.0","70.7"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-08","0","0.0","65.2"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-09","0","0.0","57.0"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-10","2","0.0","43.5"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-11","19","1.7","30.6"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2018-12","29","13.2","25.9"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPOR, UT US","2019-01","30","6.6","24.4"
"USW00024127","SALT LAKE CITY INTERNATIONAL AIRPORT UT US","2019-02","20","13.9","27.8"')

tail(avalancheobs)
str(avalancheobs)
avalancheobs$DATE<-as.factor(avalancheobs$DATE)



weather<-merge(tq,avalancheobs,by="DATE",all.x = T)
tail(weather)

DATE  avalanches   station     name dt32 snow tmin
2000-1     1       USW0021421   SL    20  15    27.4
2000-2     0   

.....

1 个答案:

答案 0 :(得分:1)

您的问题来自以下事实:两个表中的日期编码方式不同。

tq中,您可以拥有2012-1, 2012-11,而在avalancheobs中,您可以拥有2012-01, 2012-11。您需要确保在tq中将1到9的月份标上2位数字,否则表将无法匹配。

以下是解决方法:

tq$DATE = as.character(tq$DATE)
f = function(x){ paste(substr(x,1,5),"0",substr(x,6,6),sep = "")}
tq[nchar(tq$DATE) == 6,]$DATE = f(tq[nchar(tq$DATE) == 6,1])

首先,将DATE列转换为字符,然后f在日期字符串的第6个位置添加一个0(可能有更优雅的实现方式)。

此后,您的合并将起作用!

weather<-merge(tq,avalancheobs,by="DATE",all.x = T)

关于第二点,您始终可以使用dplyr::arrange

对该表进行排序
library(dplyr)
weather_sorted = arrange(weather, by = DATE)