似乎创建一个列dplyr::mutate()不允许矢量回收.为什么?
例:
require(dplyr)
df <- data_frame(id = rep(1:5, each = 42), name = rep(letters[1:7], each = 6, times = 5))
Run Code Online (Sandbox Code Playgroud)
现在:
df %>% mutate (tp = c(1:42)) #results in
Error in mutate_impl(.data, dots) :
Column `tp` must be length 210 (the number of rows) or one, not 42
Run Code Online (Sandbox Code Playgroud)
但是当然
df$tp <- c(1:42) #works
Run Code Online (Sandbox Code Playgroud)
我的变异代码是错误的还是回收根本不起作用mutate()?如果它有帮助,我使用dplyr0.7.2与RStudio 1.0.153(Mac)