Following my previous post, we have another few functions on dplyr package which will be covered in this post.
As part of data modelling, we need to sort the data to analyze further.
In T-SQL we can easily perform the sort on the data as like below. It uses “Order by” clause to sort the data.
In R, we need to use arrange function.
#Arrange
DF_Arrange<- DF_select %>%
group_by(State) %>%
summarise(Total = sum(Price)) %>%
arrange(desc(Total))
DF_Arrange
The next, very common task is to build the calculated column to satisfy the business logic. This can be easily done with the help of “mutate” function.
#mutate
DF_mutate <- DF_select %>%
group_by(State) %>%
summarise(Total = sum(Price)) %>%
mutate(“10%of Total” = Total/10) %>%
arrange(desc(Total))
DF_mutate
About the Author