dplyr v0.3 left_join错误

时间:2014-09-30 01:17:12

标签: r dplyr

尝试使用left_join参数时,我无法使用dplyr 0.3 by

首先,我根据Hadley关于github

的建议安装了v0.3
if (packageVersion("devtools") < 1.6) {
  install.packages("devtools")
}
devtools::install_github("hadley/lazyeval")
devtools::install_github("hadley/dplyr")

sessioninfo()
#    R version 3.1.1 (2014-07-10)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#
#locale:
#[1] LC_COLLATE=Portuguese_Portugal.1252  LC_CTYPE=Portuguese_Portugal.1252   
#[3] LC_MONETARY=Portuguese_Portugal.1252 LC_NUMERIC=C                        
#[5] LC_TIME=Portuguese_Portugal.1252    
#
#attached base packages:
#[1] stats     graphics  grDevices utils     datasets  methods   base     
#
#other attached packages:
#[1] dplyr_0.3
#
#loaded via a namespace (and not attached):
#[1] assertthat_0.1 DBI_0.3.1      magrittr_1.0.1 parallel_3.1.1 Rcpp_0.11.2    tools_3.1.1   

然后拿一些数据

df1<-as.tbl(data.frame('var1'=LETTERS[1:10],'value1'=sample(1:100,10), stringsAsFactors = F))
df2<-as.tbl(data.frame('var2'=LETTERS[1:10],'value2'=sample(1:100,10), stringsAsFactors = F))
library(dplyr)

最后尝试left_join

left_join(df1, df2, by = c('var1' = 'var2'))
# Error: cannot join on column 'var1'

但它适用于

df2$var1 <- df2$var2

left_join(df1, df2, by = c('var1' = 'var2'))
    Source: local data frame [10 x 4]

   var1 value1 var2 value2
1     A     37    A     48
2     B     90    B     18
3     C     13    C     36
4     D     94    D     75
5     E     14    E     12
6     F     95    F     52
7     G     60    G     55
8     H     69    H     72
9     I     25    I     49
10    J     47    J     10

我的问题

dplyr是否忽略了第二个示例中的by参数? 这可能是个错误吗?

0 个答案:

没有答案