# create two sample data frames df1 <- data.frame(x = c(1, 2, 3, 4, 5)) df2 <- data.frame(y = c(2, 4, 6, 8, 10)) print(df1) print(df2) # add a column to df1 containing the count of the number of times x is exceeded in df2 df1$count_exceed <- sapply(df1$x, function(x) sum(df2$y > x)) # print the result print(df1)