gpt4 book ai didi

使用 dplyr 的管道函数删除具有特定行号的行

转载 作者:行者123 更新时间:2023-12-04 00:12:40 24 4
gpt4 key购买 nike

我正在寻找某种方法来使用 dplyr's pipe 按行号删除特定行功能

library(dplyr)
head(mtcars)
现在假设我想删除行号 c(1, 4, 7) .通常我们会使用 mtcars[-c(1, 4, 7), ]做同样的事情。
但是我想使用 pipe做同样的事情。
有没有办法做到这一点?
任何指针都将受到高度赞赏。

最佳答案

我们可以使用 filter

library(dplyr)

# vector for rows to remove
to_remove <- c(1, 4, 7)

mtcars %>%
filter(!row_number() %in% to_remove)

关于使用 dplyr 的管道函数删除具有特定行号的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67439580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com