-1

I've this issue, with R,

I've 2 dataframes

df1
'data.frame':   5 obs. of  2 variables:
 $ col1        : num  75 90 20 25 90
 $ col3        : num  8.66 9.49 4.47 5 9.49 

df2
'data.frame':   5 obs. of  2 variables:
 $ obs       : int  1 2 3 4 5 
 $ lever     : num  0.00816 0.0113 0.32403 0.21911 0.0113 

I need to delete from df1 all values which lever in df2 are greater than 0.1 which is equivalent to 3rd and 4th values of obs in df2 right?

I should get a new dataframe df3 kind of

df3
'data.frame':   3 obs. of  2 variables:
 $ col1        : num  75 90  90 
 $ col3        : num  8.66 9.49 9.49 

I've check this link

Delete rows that exist in another data frame?

But it's not exactly the right solution.

Thank you if you can help

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Carlos Carvalho
  • 107
  • 1
  • 3
  • 11

1 Answers1

0

We can use subset. Assuming that we are comparing corresponding rows of the equal dimension datasets, use the logical expression (df2$lever <= 0.1) to subset the rows of the first dataset

df3 <- subset(df1, df2$lever  <= 0.1)
df3
#  col1 col3
#1   75 8.66
#2   90 9.49
#5   90 9.49

data

df1 <- data.frame(col1 =c(75, 90, 20, 25, 90), col3 = c(8.66, 9.49, 4.47, 5, 9.49))
df2 <- data.frame(obs = 1:5, lever = c(0.00816, 0.0133, 0.32403, 0.21911, 0.0113))
akrun
  • 874,273
  • 37
  • 540
  • 662