userJT userJT - 1 year ago 54
R Question

Using dplyr::filter, how can the output be limited to just first 500 rows?

dplyr is a great and fast library.

Using the %.% operator enables powerful manipulation.

In my first step, I need to limit the output to only 500 rows max (for display purposes).

How can I do that?

par<-filter(pc,Child_Concept_GID==as.character(mcode)) %>% select(Parent_Concept_GID)

what I need is something like


Is there direct way or a nice workaround without making the first step a separate step (outside the %>% "stream")

Answer Source

To limit the output of filter, one can add after filter a function


credit goes to commenter joran


par<-filter(pc,Child_Concept_GID==as.character(mcode)) %>% top_n(500) %>% select(Parent_Concept_GID)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download