Search code examples
rdataframedelete-row

Delete rows below one in r


I want to delete rows below a specific one. Let's suppose I have two data frames where I always extract the first value:

df1[1,1]

[1,1]= 153548

Based on that value which will be found somewhere in the first column of another data frame, I want to keep all rows above that same value and delete everything below.


Solution

  • If you mean "keep all rows above the place where that same value is", then maybe you can try

    df2[cumsum(df2[,1]==df1[1,1])==0,]