I have a dataframe (DF) with many columns (colA, colB, colC, colD, . . . . ). I would like to apply the na.approx function, with group_by, to several, but not all, columns in the dataframe. I succeeded in applying the na.approx and group_by functions on one column with the following:
DFxna<-DF %>% group_by(colA) %>% mutate(colB = na.approx(colB, na.rm = FALSE, maxgap=4))
However, I was not able to create a code that would apply to several, specified, columns. I thought that lapply would be appropriate, and tried several times, unsuccesfully, to use lapply.