8/28/2023 0 Comments Dplyr summarize![]() ![]() # Select columns by name starwars %>% select(hair_color, skin_color, eye_color) #> # A tibble: 87 × 3 #> hair_color skin_color eye_color #> #> 1 blond fair blue #> 2 gold yellow #> 3 white, blue red #> 4 none white yellow #> # ℹ 83 more rows # Select all columns between hair_color and eye_color (inclusive) starwars %>% select(hair_color :eye_color) #> # A tibble: 87 × 3 #> hair_color skin_color eye_color #> #> 1 blond fair blue #> 2 gold yellow #> 3 white, blue red #> 4 none white yellow #> # ℹ 83 more rows # Select all columns except those from hair_color to eye_color (inclusive) starwars %>% select( !(hair_color :eye_color)) #> # A tibble: 87 × 11 #> name height mass birth_year sex gender homeworld species films vehicles #> #> 1 Luke Sk… 172 77 19 male mascu… Tatooine Human #> 2 C-3PO 167 75 112 none mascu… Tatooine Droid #> 3 R2-D2 96 32 33 none mascu… Naboo Droid #> 4 Darth V… 202 136 41.9 male mascu… Tatooine Human #> # ℹ 83 more rows #> # ℹ 1 more variable: starships # Select all columns ending with color starwars %>% select( ends_with( "color")) #> # A tibble: 87 × 3 #> hair_color skin_color eye_color #> #> 1 blond fair blue #> 2 gold yellow #> 3 white, blue red #> 4 none white yellow #> # ℹ 83 more rows With highest or lowest values of a variable. slice_min() and slice_max() select rows.Needed, you can weight the sample with the weight Use replace = TRUE to perform a bootstrap sample. ![]() ![]() Starwars %>% slice_sample( n = 5) #> # A tibble: 5 × 14 #> name height mass hair_color skin_color eye_color birth_year sex gender #> #> 1 Dud Bolt 94 45 none blue, grey yellow NA male mascu… #> 2 Bossk 190 113 none green red 53 male mascu… #> 3 Shaak Ti 178 57 none red, blue,… black NA fema… femin… #> 4 Dormé 165 NA brown light brown NA fema… femin… #> # ℹ 1 more row #> # ℹ 5 more variables: homeworld, species, films, #> # vehicles, starships starwars %>% slice_sample( prop = 0.1) #> # A tibble: 8 × 14 #> name height mass hair_color skin_color eye_color birth_year sex gender #> #> 1 Qui-Gon … 193 89 brown fair blue 92 male mascu… #> 2 Dexter J… 198 102 none brown yellow NA male mascu… #> 3 R4-P17 96 NA none silver, r… red, blue NA none femin… #> 4 Lama Su 229 88 none grey black NA male mascu… #> # ℹ 4 more rows #> # ℹ 5 more variables: homeworld, species, films, #> # vehicles, starships ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |