【发布时间】:2018-05-11 23:56:23
【问题描述】:
问题
我想对两个数据帧进行完全连接,以便将仅包含一行的观察数据和其中包含数据的几个向量复制到另一个数据帧中所有观察的多行中。这两个数据框由“site”和“lib”匹配。
library(data.table); library(magrittr); library(dplyr)
df1<-structure(list(lib = c(10118L, 10118L, 10118L, 10104L, 10104L, 10104L ), site = c("yanglingshaanxi", "yanglingshaanxi", "yanglingshaanxi", "tianjin", "tianjin", "tianjin"), y = c(1.896017347, 0.919531829, 1.150194405, 2.164771575, 1.060472222, 1.372680891), yr = c("1991", "1992", "1993", "2009", "2010", "2012")), .Names = c( "lib", "site", "y","yr"), class = c("data.table", "data.frame"), row.names = c(NA, -6L))
df2<-structure(list(yr = c(NA_integer_, NA_integer_), lib = c(10104L, 10118L), site = c("tianjin", "yanglingshaanxi"), y = c(NA_real_, NA_real_)), .Names = c("yr", "lib", "site", "y"), class = "data.frame", row.names = c(10695L, 10698L))
y<-full_join(df1, df2,by=c("site","lib")) %>%
mutate(
yr=coalesce(yr.x,yr.y), #there are way more vectors that i'm actually coalescing than this it that matters
y=coalesce(y.x,y.y)
) %>%
select(-c(
yr.x,yr.y,
y.x,y.y,
lib ))
如何消除此错误?
Error in mutate_impl(.data, dots) :
Evaluation error: Argument 2 must be type integer, not character.
In addition: Warning message:
package ‘bindrcpp’ was built under R version 3.3.3
我可以发誓自从几个月前使用它以来我没有碰过它——我现在是按错误的顺序加载包裹还是什么? “论据2”甚至指的是什么?
目前接近
尝试先加载 plyr,然后加载 dplyr;然后尝试仅加载 dplyr。尝试查看this (dissimilar) question。试图在??mutate中查找错误消息所指的内容,试图通过查看源代码
> getAnywhere(mutate)
A single object matching ‘mutate’ was found
It was found in the following places
package:dplyr
namespace:dplyr
with value
function (.data, ...)
{
UseMethod("mutate")
}
【问题讨论】: