ARIMITRA MAITI
ARIMITRA MAITI

Reputation: 323

dplyr subquery inside join function

The ususal syntax of dplyr join functions are

left_join(df1, df2, by = c("Key"))

considering the fact same key exists in both datasets. Is there a way to write pipe operators inside join functions instead of creating another dataset? E.g

df1 %>% mutate(something = some_calc) %>% filter(some filter) left_join(df2 %>% mutate(some filter), by c("key"))

I am getting out of bounds error while joining.

Upvotes: 1

Views: 1584

Answers (1)

Axeman
Axeman

Reputation: 35187

df1 %>% 
  mutate(something = some_calc) %>% 
  filter(some filter) %>% 
  left_join(df2 %>% mutate(some filter), by = c("key"))

Should work.

Upvotes: 1

Related Questions