![]() ![]() Select can also be used to rearrange the order of columns: hamsters # A tibble: 5 x 4 ![]() Select(-gender, -hamster_cages) # A tibble: 5 x 2 ![]() We also could have gotten just the name and hamsters columns by removing the gender and hamster_cages columns: hamsters # A tibble: 5 x 4 We can use a “-” to get rid of a column and leave the rest of the columns: hamsters # A tibble: 5 x 4 For example, maybe we want just the name and hamsters columns: hamsters # A tibble: 5 x 4 Select is used to choose which columns to work with. Self-explanation: Why do Karl and Jen switch positions in the following two data frames? hamsters %>%Īrrange(hamster_cages) # A tibble: 5 x 4Īrrange(hamster_cages, hamsters) # A tibble: 5 x 4 If we input multiple column names, arrange uses the additional columns to break ties. We can instead arrange in descending order with the desc() function: hamsters %>%Īrrange(desc(hamster_cages)) # A tibble: 5 x 4Ĭharacter columns get arranged in alaphetical order: hamsters %>% This is the same thing that the “sort” feature in Excel does.īy default, arranging happens in ascending order or from low to high: hamsters # A tibble: 5 x 4 Before doing something with hamsters, I’ll typically print the original hamsters data frame first because the easiest way to see what a function is doing is to see a before and after.Īrrange keeps all of the information in the data frame, but just changes the order of the rows. The code blocks below will show small little examples of what is possible. Now that we have a data frame to work with, we can dive into the 5 verbs of dplyr. This article will cover the five verbs of dplyr: select, filter, arrange, mutate, and summarize.īefore we walk through each command, let’s make a data frame to play with. The magic of dplyr is that with just a handful of commands (the verbs of dplyr), you can do nearly anything you’d want to do with your data. Think of the d as standing for data and the plyr standing for plyers – the goal of this package is to manipulate data frames in useful ways. One of the key packages in that collection is called dplyr. The Tidyverse is a collection of packages made by Hadley Wickham. Note: If you haven’t yet installed the tidyverse, you’ll first have to run the code install.packages(“tidyverse”). As always, the first thing we will do is load the tidyverse. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |