Skip to contents

Nests species columns obtained when reading structured data from the kobo landings survey

Usage

pt_nest_species(x)

Arguments

x

A data frame containing raw landings data from the Timor operations.

Value

Landings data in which the information about multiple species has been nested into a single column (species_group) this column contains a tibble for every row. This, species tibble has as many rows as there are species. In turn, the data frames contained in species_group contain a column called length_individuals where a data frame with the number of individuals per length is stored

Details

One of the disadvantages of using structured survey data is that the tables can become very wide (many columns). This happens when question groups or other fields can be recorded multiple times. For example in the landings survey, for each species captured, about 17 questions are recorded. There is no limit to the number of species that can be recorded in the trip. If, for example a survey records seven species we will have over a hundred columns in the data corresponding to species information.

To improve that situation an avoid using multiple tables we use nested data frames (see tidyr::nest). In nested data frames columns can be lists and can contain arbitrary information, like other data frames, lists, vectors, or models.

Examples

dummy_landings <- tidyr::tibble(
  `_id` = "123",
  `species_group.0.species_group/species` = "sp01",
  `species_group.0.species_group/food_or_sale` = "food",
  `species_group.0.species_group/no_fish_by_length_group/no_individuals_10_15` = 10,
  `species_group.0.species_group/no_fish_by_length_group/no_individuals_5_10` = 10,
  `species_group.0.species_group/no_fish_by_length_group/fish_length_over60` = 80,
  `species_group.0.species_group/no_fish_by_length_group/no_individuals_over60` = 1,
  `species_group.1.species_group/species` = "sp02",
  `species_group.1.species_group/food_or_sale` = "sale",
  `species_group.1.species_group/no_fish_by_length_group/no_individuals_20_25` = 5,
  `species_group.1.species_group/no_fish_by_length_group/no_individuals_5_10` = 20,
  `species_group.1.species_group/no_fish_by_length_group/fish_length_over60` = 70,
  `species_group.1.species_group/no_fish_by_length_group/no_individuals_over60` = 2
)
pt_nest_species(dummy_landings)
#> # A tibble: 1 × 2
#>   `_id` species_group   
#>   <chr> <list>          
#> 1 123   <tibble [2 × 4]>