【问题标题】:Error in mutate_impl(.data, dots) : Evaluation error: Argument 2 must be type charactermutate_impl(.data, dots) 中的错误:评估错误:参数 2 必须是类型字符
【发布时间】: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")
}

【问题讨论】:

    标签: r coalesce dplyr


    【解决方案1】:

    “Argument 2”显然只是指在一个数据帧中重新制作并合并的向量。我开始认为可能是这种情况,所以我通过蛮力找到了它们各自数据帧中的整数和字符向量,只需向下查看约 30 个被合并的向量列表并注释掉它们,找出哪些向量使代码再次工作他们“关闭”了。 所以,这修复了它:在有问题的数据框中将“yr”更改为整数:

    df1$yr<-as.integer(as.character(df1$yr))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 2018-10-19
      相关资源
      最近更新 更多