Error in FUN(left, right) : operations are possible only for numeric, logical or complex types

I kept getting the above error in my code below, wherein I was trying to use filter:

#Not working:
postings_filt <- postings %>% filter(postings, Expense_Type == 'Return')

Eventually the above worked only after I removed the initial pipe in of the data frame I was trying to work on. Just trying to understand why the above pipe in did not work?

#Working:
postings_filt <- filter(postings, Expense_Type == 'Return')

Because the pipe operator passes the previous object as the first argument for the next function so you were passing postings twice, equivalent to this

postings_filt <- filter(postings, postings, Expense_Type == 'Return')

The correct way would be

postings_filt <- postings %>% 
    filter(Expense_Type == 'Return')

Thanks for clarifying on this!

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