且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

R-如何删除单个列中某个特定短语之前和之后的行

更新时间:2023-09-23 13:23:40

使用grep,您可以找到找到您的模式的行的索引:

Using grep, you can locate the indexes of the rows where your pattern is found:

ind=grep("^GMT",df$type)

然后,您只能保留两个索引之间的行:

Then you can keep only the rows between the two indexes:

df=df[ind[1]:ind[2],]