| append() | 进行元素的追加 |
list1 <- list(1,2) %>%
print()
list1 <- list(3,4) %>% #如果直接加,就会覆盖
print()
list1 <- append(list1,c(5,6)) %>% # 使用append()就能在其后追加,而不是覆盖了
print()
运行结果如下:
> list1 <- list(1,2) %>%
+ print()
[[1]]
[1] 1
[[2]]
[1] 2
> list1 <- list(3,4) %>% #如果直接加,就会覆盖
+ print()
[[1]]
[1] 3
[[2]]
[1] 4
> list1 <- append(list1,c(5,6)) %>% # 使用append()就能在其后追加,而不是覆盖了
+ print()
[[1]]
[1] 3
[[2]]
[1] 4
[[3]]
[1] 5
[[4]]
[1] 6
本文介绍了R语言中如何利用append()函数实现列表元素的追加操作,避免直接赋值导致的数据覆盖问题,并通过示例展示了append()函数的具体用法。
2725

被折叠的 条评论
为什么被折叠?



