楼主你好 r文件格式上传不支持 复制粘贴试一下以下代码 看看我x和y的数据是不是大概和你的datasets一个意思 我测试成功 没有error。merge这个function是不用在意行数问题的!楼上回复的那位是正确的。
x <- data.frame("year" = c(1996,1996,1997,1997,1998,1998,1998), "code" = c(11,12,12,12,12,13,13), "asset" = c(11112:11118))
y <- data.frame("year" = c(1996,1996,1997,1998,1998), "code" = c(11,12,12,12,13), "output" = c(4285287,248283,23847,143871,192837))
View(x)
View(y)
#this should be what you want
x_y <- merge(x,y,by=c("year","code"))
#use the following code when some rows of x have no matching rows in y by "year" and "code"
#it will still append the non-matching rows
x_y <- merge(x,y,by=c("year","code"),all.x = TRUE)
View(x_y)
如果你还测试不行的话 可以把原dataset发给我 我来试试看



雷达卡


京公网安备 11010802022788号







