R/helpers_grouped_functions.R
grouped_list.Rd
This function splits the dataframe into a list, with the length of the list equal to the factor levels of the grouping variable. Each element of the list will be a tibble.
grouped_list(data, grouping.var = NULL)
data | A dataframe (or a tibble) from which variables specified are to be taken. A matrix or tables will not be accepted. |
---|---|
grouping.var | A single grouping variable (can be entered either as a
bare name |
#> $carni #> # A tibble: 19 x 11 #> name genus vore order conservation #> <chr> <chr> <chr> <chr> <chr> #> 1 Cheetah Acinonyx carni Carnivora lc #> 2 Northern fur seal Callorhinus carni Carnivora vu #> 3 Dog Canis carni Carnivora domesticated #> 4 Long-nosed armadillo Dasypus carni Cingulata lc #> 5 Domestic cat Felis carni Carnivora domesticated #> 6 Pilot whale Globicephalus carni Cetacea cd #> 7 Gray seal Haliochoerus carni Carnivora lc #> 8 Thick-tailed opposum Lutreolina carni Didelphimorphia lc #> 9 Slow loris Nyctibeus carni Primates NA #> 10 Northern grasshopper mouse Onychomys carni Rodentia lc #> 11 Tiger Panthera carni Carnivora en #> 12 Jaguar Panthera carni Carnivora nt #> 13 Lion Panthera carni Carnivora vu #> 14 Caspian seal Phoca carni Carnivora vu #> 15 Common porpoise Phocoena carni Cetacea vu #> 16 Bottle-nosed dolphin Tursiops carni Cetacea NA #> 17 Genet Genetta carni Carnivora NA #> 18 Arctic fox Vulpes carni Carnivora NA #> 19 Red fox Vulpes carni Carnivora NA #> sleep_total sleep_rem sleep_cycle awake brainwt bodywt #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 12.1 NA NA 11.9 NA 50 #> 2 8.7 1.4 0.383 15.3 NA 20.5 #> 3 10.1 2.9 0.333 13.9 0.07 14 #> 4 17.4 3.1 0.383 6.6 0.0108 3.5 #> 5 12.5 3.2 0.417 11.5 0.0256 3.3 #> 6 2.7 0.1 NA 21.4 NA 800 #> 7 6.2 1.5 NA 17.8 0.325 85 #> 8 19.4 6.6 NA 4.6 NA 0.37 #> 9 11 NA NA 13 0.0125 1.4 #> 10 14.5 NA NA 9.5 NA 0.028 #> 11 15.8 NA NA 8.2 NA 163. #> 12 10.4 NA NA 13.6 0.157 100 #> 13 13.5 NA NA 10.5 NA 161. #> 14 3.5 0.4 NA 20.5 NA 86 #> 15 5.6 NA NA 18.4 NA 53.2 #> 16 5.2 NA NA 18.8 NA 173. #> 17 6.3 1.3 NA 17.7 0.0175 2 #> 18 12.5 NA NA 11.5 0.0445 3.38 #> 19 9.8 2.4 0.35 14.2 0.0504 4.23 #> #> $herbi #> # A tibble: 32 x 11 #> name genus vore order conservation sleep_total #> <chr> <chr> <chr> <chr> <chr> <dbl> #> 1 Mountain beaver Aplodontia herbi Rodentia nt 14.4 #> 2 Cow Bos herbi Artiodactyla domesticated 4 #> 3 Three-toed sloth Bradypus herbi Pilosa NA 14.4 #> 4 Roe deer Capreolus herbi Artiodactyla lc 3 #> 5 Goat Capri herbi Artiodactyla lc 5.3 #> 6 Guinea pig Cavis herbi Rodentia domesticated 9.4 #> 7 Chinchilla Chinchilla herbi Rodentia domesticated 12.5 #> 8 Tree hyrax Dendrohyrax herbi Hyracoidea lc 5.3 #> 9 Asian elephant Elephas herbi Proboscidea en 3.9 #> 10 Horse Equus herbi Perissodactyla domesticated 2.9 #> sleep_rem sleep_cycle awake brainwt bodywt #> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 2.4 NA 9.6 NA 1.35 #> 2 0.7 0.667 20 0.423 600 #> 3 2.2 0.767 9.6 NA 3.85 #> 4 NA NA 21 0.0982 14.8 #> 5 0.6 NA 18.7 0.115 33.5 #> 6 0.8 0.217 14.6 0.0055 0.728 #> 7 1.5 0.117 11.5 0.0064 0.42 #> 8 0.5 NA 18.7 0.0123 2.95 #> 9 NA NA 20.1 4.60 2547 #> 10 0.6 1 21.1 0.655 521 #> # ... with 22 more rows #> #> $insecti #> # A tibble: 5 x 11 #> name genus vore order conservation #> <chr> <chr> <chr> <chr> <chr> #> 1 Big brown bat Eptesicus insecti Chiroptera lc #> 2 Little brown bat Myotis insecti Chiroptera NA #> 3 Giant armadillo Priodontes insecti Cingulata en #> 4 Eastern american mole Scalopus insecti Soricomorpha lc #> 5 Short-nosed echidna Tachyglossus insecti Monotremata NA #> sleep_total sleep_rem sleep_cycle awake brainwt bodywt #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 19.7 3.9 0.117 4.3 0.000300 0.023 #> 2 19.9 2 0.2 4.1 0.00025 0.01 #> 3 18.1 6.1 NA 5.9 0.081 60 #> 4 8.4 2.1 0.167 15.6 0.00120 0.075 #> 5 8.6 NA NA 15.4 0.025 4.5 #> #> $omni #> # A tibble: 20 x 11 #> name genus vore order conservation #> <chr> <chr> <chr> <chr> <chr> #> 1 Owl monkey Aotus omni Primates NA #> 2 Greater short-tailed shrew Blarina omni Soricomorpha lc #> 3 Grivet Cercopithecus omni Primates lc #> 4 Star-nosed mole Condylura omni Soricomorpha lc #> 5 African giant pouched rat Cricetomys omni Rodentia NA #> 6 Lesser short-tailed shrew Cryptotis omni Soricomorpha lc #> 7 North American Opossum Didelphis omni Didelphimorphia lc #> 8 European hedgehog Erinaceus omni Erinaceomorpha lc #> 9 Patas monkey Erythrocebus omni Primates lc #> 10 Galago Galago omni Primates NA #> 11 Human Homo omni Primates NA #> 12 Macaque Macaca omni Primates NA #> 13 Chimpanzee Pan omni Primates NA #> 14 Baboon Papio omni Primates NA #> 15 Potto Perodicticus omni Primates lc #> 16 African striped mouse Rhabdomys omni Rodentia NA #> 17 Squirrel monkey Saimiri omni Primates NA #> 18 Pig Sus omni Artiodactyla domesticated #> 19 Tenrec Tenrec omni Afrosoricida NA #> 20 Tree shrew Tupaia omni Scandentia NA #> sleep_total sleep_rem sleep_cycle awake brainwt bodywt #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 17 1.8 NA 7 0.0155 0.48 #> 2 14.9 2.3 0.133 9.1 0.00029 0.019 #> 3 10 0.7 NA 14 NA 4.75 #> 4 10.3 2.2 NA 13.7 0.001 0.06 #> 5 8.3 2 NA 15.7 0.0066 1 #> 6 9.1 1.4 0.15 14.9 0.000140 0.005 #> 7 18 4.9 0.333 6 0.0063 1.7 #> 8 10.1 3.5 0.283 13.9 0.0035 0.77 #> 9 10.9 1.1 NA 13.1 0.115 10 #> 10 9.8 1.1 0.55 14.2 0.005 0.2 #> 11 8 1.9 1.5 16 1.32 62 #> 12 10.1 1.2 0.75 13.9 0.179 6.8 #> 13 9.7 1.4 1.42 14.3 0.44 52.2 #> 14 9.4 1 0.667 14.6 0.18 25.2 #> 15 11 NA NA 13 NA 1.1 #> 16 8.7 NA NA 15.3 NA 0.044 #> 17 9.6 1.4 NA 14.4 0.02 0.743 #> 18 9.1 2.4 0.5 14.9 0.18 86.2 #> 19 15.6 2.3 NA 8.4 0.0026 0.9 #> 20 8.9 2.6 0.233 15.1 0.0025 0.104 #># }