-
Book Overview & Buying
-
Table Of Contents
R for Data Science Cookbook (n)
By :
To perform multiple operations on data using dplyr, we can wrap up the function calls into a larger function call. Or, we can use the %>% chaining operator to chain operations instead. In this recipe, we introduced how to chain operations when using dplyr.
Ensure that you completed the Enhancing a data.frame with a data.table recipe to load purchase_view.tab and purchase_order.tab as both data.frame and data.table into your R environment.
Perform the following steps to subset and slice data with dplyr:
In R, to sum up a sequence from 1 to 10, we can wrap the series of 1 to 10 with the sum function:
> sum(1:10) [1] 55
Alternatively, we can use a chaining operator to chain operations:
> 1:10 %>% sum() [1] 55
To select and filter data with dplyr, we can wrap the filtered data in a select function:
> select.p.price.over.1000 <- select(filter(order.dt, Price >= 1000 ), contains('P') ) > head(select.p.price.over.1000,...
Change the font size
Change margin width
Change background colour