library(dplyr)
a <- data_frame(id = c("A","A","A","B","B","B"),
b = c(1.2, 1.5, 1.8, 1.1, 1.6, 1.4))
Now, I´d like to retrieve the values closest to 1.43 for each of the catergories in id. I thought I could use:
a %>% group_by(id) %>% nth(which.min(abs(.$b-1.43)))
but dplyr states
Error: Don't know how to generate default for object of class grouped_df/tbl_df/tbl/data.frame