Note that the tidyverse also includes a graphing package, ggplot2, which we introduce later in Chapter 8 in the Data Visualization part of the book the readr package discussed in Chapter 5 and many others. We will learn how to implement the tidyverse approach throughout the book, but before delving into the details, in this chapter we introduce some of the most widely used tidyverse functionality, starting with the dplyr package for manipulating data frames and the purrr package for working with functions. # ℹ Use the ]8 conflicted package]8 to force all conflicts to become errors # ✖ dplyr::filter() masks stats::filter() We will focus on a specific data format referred to as tidy and on specific collection of packages that are particularly helpful for working with tidy data referred to as the tidyverse. We will be using data frames for the majority of this book. In this chapter we learn to work directly with data frames, which greatly facilitate the organization of information. However, once we start more advanced analyses, the preferred unit for data storage is not the vector but the data frame. Up to now we have been manipulating vectors by reordering and subsetting them through indexing. Arrange| as_tibble| between| case_when| filter| group_by| mutate| %>% or |>| pull| quantile| rank| sapply| select| slice_max| slice_min| summarize| tibble| The sort argument is useful if you want to see theīy_species %>% arrange ( desc ( mass ) ) %>% relocate ( species, mass ) #> # A tibble: 87 × 14 #> # Groups: species #> species mass name height hair_color skin_color eye_color birth_year #> #> 1 Hutt 1358 Jabba D… 175 NA green-tan… orange 600 #> 2 Kaleesh 159 Grievous 216 none brown, wh… green, y… NA #> 3 Droid 140 IG-88 200 none metal red 15 #> 4 Human 136 Darth V… 202 none white yellow 41.9 #> # ℹ 83 more rows #> # ℹ 6 more variables: sex, gender, homeworld, #> # films, vehicles, starships by_species %>% arrange ( desc ( mass ). Or use tally() to count the number of rows in each By_species #> # A tibble: 87 × 14 #> # Groups: species #> name height mass hair_color skin_color eye_color birth_year sex #> #> 1 Luke Skyw… 172 77 blond fair blue 19 male #> 2 C-3PO 167 75 NA gold yellow 112 none #> 3 R2-D2 96 32 NA white, bl… red 33 none #> 4 Darth Vad… 202 136 none white yellow 41.9 male #> # ℹ 83 more rows #> # ℹ 6 more variables: gender, homeworld, species, #> # films, vehicles, starships by_sex_gender #> # A tibble: 87 × 14 #> # Groups: sex, gender #> name height mass hair_color skin_color eye_color birth_year sex #> #> 1 Luke Skyw… 172 77 blond fair blue 19 male #> 2 C-3PO 167 75 NA gold yellow 112 none #> 3 R2-D2 96 32 NA white, bl… red 33 none #> 4 Darth Vad… 202 136 none white yellow 41.9 male #> # ℹ 83 more rows #> # ℹ 6 more variables: gender, homeworld, species, #> # films, vehicles, starships
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |