我想删除数据框列中某个字符串出现后的所有行。我只想返回出现在 A 列中“总计”上方的 3 行。出现在“总计”下方的 2 行将被排除。
A B
Bob Smith 01005
Carl Jones 01008
Syndey Lewis 01185
total
Adam Price 01555
Megan Watson 02548
最佳答案
我们可以用 row_number
和 which
进行子集化
library(dplyr)
df %>% filter(row_number() < which(A=='total'))
A B
1 Bob Smith 01005
2 Carl Jones 01008
3 Syndey Lewis 01185
关于删除字符串 R 数据帧之后出现的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69121610/