这是我的例子:
library(dplyr)
my_df <- data.frame( col_1 = I(list(c(1,2), 1 )), col_2 = c(1,2))
my_df <- my_df %>% rowwise(diff = setdiff(col_1, col_2))
它会产生一个错误:
Error in rowwise(., diff = setdiff(col_1, col_2)) :
unused argument (diff = setdiff(col_1, col_2))
出了什么问题以及如何解决?有什么想法吗?
更新:我的错,我只是忘了添加mutate
my_df <- data.frame( col_1 = I(list(c(1,2), 1 )), col_2 = c(1,2))
my_df <- my_df %>% rowwise() %>% mutate(diff = setdiff(col_1, col_2))