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:
func<-function(drv,cty){
values<-which(drv=="f"& cty<20)
cty[values]<-0
cty}
Only on these manufacturers
manufacturers_vector<-c("audi","chevrolet","jeep")
There is any way I can apply the function only if the manufacturer column in my df matches a value in manufacturers_vector?
to
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.
system
Closed
5
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.