sort ranges from data frame

Hello Community,
I'm new to Rstudio and I have a problem with it,

I have two data frames and I want to compare two columns and sorting out similar values with a range that I can define.
For example,
df1 df2
1 1.5
6 20
10 12
3 60

in this example if the range is +/- 2 , I have to be able to sort out the first and forth values along with other informations contained in columns B and C

I appreciate your help


The format of your data is not very clear to me. Are df1 and df2 two distinct data frames? Also A, B and C are repeated twice. Does each dataset have 3 columns? You could create a data frame with data.frame() and post your code so that we can replicate it.

Thank you for your answer Gueyenono,
I found the answer,

range = 100
df1 = 0 ## this is the dataframe that we will extract the required rows

j = 0
for (i in 1:nrow(df)){
if(abs(df$distanceToTSS[i] - df$distanceToTSS.1[i])<range){
df1= df[i,]
df1 = rbind(df[i,],df1)

Happy new year :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.