我没问题把它做出来:
library(dplyr)
library(tibble)
as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp)它们产生的结果是:
# A tibble: 2 × 3
cyl disp cyl_x_disp
<dbl> <dbl> <dbl>
1 6 160 960
2 4 108 432但是当我试图用reprex包起来时
reprex::reprex(as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp))剪贴板显示如下:
as.tibble(mtcars[2:3, 2:3]) %>% mutate(cyl_x_disp = cyl * disp)
#> Error in eval(expr, envir, enclos): could not find function "%>%"正确的方法是什么?
发布于 2017-04-21 01:25:41
您也应该将包加载放到表达式中,否则示例是不可复制的:
reprex::reprex({
library(tibble)
library(dplyr)
as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp)
})这将产生:
library(tibble)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
as.tibble(mtcars[2:3, 2:3]) %>% mutate(cyl_x_disp = cyl * disp)
#> # A tibble: 2 × 3
#> cyl disp cyl_x_disp
#> <dbl> <dbl> <dbl>
#> 1 6 160 960
#> 2 4 108 432https://stackoverflow.com/questions/43532098
复制相似问题