DataTaunew | comments | leaders | submitlogin
1 point by rlayton 3337 days ago | link | parent

(Never used R) What does >%> do? My best guess would be that is performs the modulo operation, but that doesn't fit with your comment.


4 points by kiyoto 3337 days ago | link

It's the "pipe" operation. So, if you do

data %>% group_by(column)

That's the same as

group_by(data, column)

Essentially, this allows computations to be written with few nesting like

data %>% group_by(column) %>% summarise(f = length(another_c0lumn) %>% filter(f > 20)

A similar idea in other languages is method-chaining, which is what pandas does to implement something similar.

I personally like "%>%" better than method-chaining, probably because I think more functionally than OOP. But I now feel like I am opening a different can of worms.

-----

1 point by ubercode5 3336 days ago | link

I am with you there, piping is a very powerful operation and makes more sense from a purely functional perspective.

Method chaining isn't too terrible, but it also means those functions need to be attached to the object, which makes it rigid to reusably extend if you aren't the author. Maybe we should petition the python community for piping :).

The even more ugly option would be function nesting a(b(c(data))), which feels like reading reverse polish notation..

-----




RSS | Announcements