Apply a function on certain rows of a dataframe

Hi, I am trying to apply linear interpolation on a column EVI of a dataframe df. However, the column EVI has three distinct year classes (2015, 2016 and 2017). The code below (na.approx) applies to the whole column. I want to apply the linear interpolation function on different years (2015, 2016, 2017) for a single column.

# This function applies the linear interpolation on the whole column
df$EVI<- na.approx(df$EVI,  na.rm= FALSE, maxgp =Inf, rule =2)
#I want apply the function on different years for 2015, 2016 and 2017

To apply a function to a group of rows within a data.frame I would use dplyr group_modify

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.