我有以下小标题:
temp <- structure(list(x = list(1:10, 1:10), y = list(c(3L, 9L, 10L,
8L, 1L), c(1L, 3L, 5L, 2L, 4L))), .Names = c("x", "y"), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -2L))
> temp
# A tibble: 2 x 2
x y
<list> <list>
1 <int [10]> <int [5]>
2 <int [10]> <int [5]>
我想创建一个新列z
,它是列中列表元素的 setdiffx
和y
,这样temp$z
应该输出为:
> temp$z
[[1]]
[1] 2 4 5 6 7
[[2]]
[1] 6 7 8 9 10
和 temp 将更新为:
> temp
# A tibble: 2 x 3
x y z
<list> <list> <list>
1 <int [10]> <int [5]> <int [5]>
2 <int [10]> <int [5]> <int [5]>
PS:一个 dplyr 解决方案会很棒!:-)