Map Filter And Reduce Function In R