You can calculate the absolute difference and use which.minto find the least difference index
df[which.min(abs(150-df$accumulated_visits)),]
OR, when sorting accumulated_visits, you can also usefindInterval
df[findInterval(150, df$accumulated_visits),]
DATA
df = structure(list(date = c("01-01", "01-02", "01-03", "01-04", "01-05",
"01-06"), accumulated_visits = c(102L, 134L, 148L, 159L, 162L,
175L)), .Names = c("date", "accumulated_visits"), class = "data.frame", row.names = c(NA,
-6L))
source
share