仅删除满足条件的数据框的第一行

Delete only the first row of dataframe that satisfies a condition

我只想根据一种情况删除数据帧中的一行。

但现有代码将删除所有包含此条件的行。但是我只想删除满足条件的第一行。

我该怎么做?

下面是一个如何删除匹配元素的第一个实例的示例:

> df <- data.frame(x=rep(1:3,3))
> df[,'x']
[1] 1 2 3 1 2 3 1 2 3
> df[which(df$x==2)[1],'x']
[1] 2
> df[-which(df$x==2)[1],'x']
[1] 1 3 1 2 3 1 2 3