![]() ![]() I am experiencing an issue where groupby() > summarize() works with the object after it is converted to a data frame, but not as an sf. The solution does what I want but its not very efficient. 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 ). However, I am having crippling difficulties doing standard groupby() > summarize() > mutate() processes with data stored as sf. Or use tally() to count the number of rows in each This shortcut avoids to use groupby and returns an ungrouped data frame: library(dplyr) x > summarise(Frequency sum(Frequency). Im trying to sum sub groups with dplyr using mutate, but this means I need to know each row group to create a conditional. 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. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |