Apply a conditional function in a nested dataframe

Hi there. I have a nested dataframe like this:

df<-mpg %>% group_by(manufacturer) %>% nest()

And I have to apply this function to clean some values:

  values<-which(drv=="f"& cty<20)

Only on these manufacturers


There is any way I can apply the function only if the manufacturer column in my df matches a value in manufacturers_vector?


df<-mpg %>% 
  filter(manufacturer %in% manufacturer_vector) %>%
  group_by(manufacturer) %>% nest()

Thank you.
In that way I would be discarding all other values (the ones not affected by my filter). There is any way to keep them?

Reverse the filter to make a second df and then

dplyr::inner_join(df1,df2, key=“...”)

where ... is the common variable with unique values.

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.