Multiple geocodes can be stored as rows in a single data frame or as a named list of one row data frames. As metadata attributes lists are easier to manipulate, but when computing the sun position data frames are more efficient. These functions implement conversions between objects using these two approaches.
Usage
split_geocodes(geocode, idx = "spct.idx", simplify = TRUE)
bind_geocodes(geocode, idx = "spct.idx")Arguments
- geocode
data.frame with geocode data in columns
"lat","lon", and possibly also"address".- idx
character Name of the column where the ID factor is stored in geocode data frames with multiple rows.
- simplify
logical Flag indicating if when the list to be returnes has a single member, the member geocode should be returned instead.
Details
Function split_geocodes() splits a multi-row data.frame
containing one geocode per row and a character vector or a
factor as ID column into a named list of one row data
frames containing the same geocode information. If the input is a
single-row data frame or a list with a single member, and
simplify = TRUE is passed in the call, a bare data frame is
returned, with the ID column, if present, deleted.
Function bind_geocodes() binds the geocodes members of a
list into a multirow data.frame containing one geocode per row and
a character vector ID column containing the same geocode
information.
Examples
my.geocodes <- data.frame(lon = c(0, 10, 15),
lat = c(30, 60, 89),
address = c("one", "two", "three"),
spct.idx = c("A", "B", "C"))
split_geocodes(my.geocodes)
#> $A
#> # A tibble: 1 × 3
#> lon lat address
#> <dbl> <dbl> <chr>
#> 1 0 30 one
#>
#> $B
#> # A tibble: 1 × 3
#> lon lat address
#> <dbl> <dbl> <chr>
#> 1 10 60 two
#>
#> $C
#> # A tibble: 1 × 3
#> lon lat address
#> <dbl> <dbl> <chr>
#> 1 15 89 three
#>
split_geocodes(my.geocodes[1, ])
#> # A tibble: 1 × 3
#> lon lat address
#> <dbl> <dbl> <chr>
#> 1 0 30 one
my.list <- list("A" = data.frame(lon = 10,
lat = 30,
address = "North"),
"B" = data.frame(lon = -10,
lat = -30,
address = "South"))
bind_geocodes(my.list)
#> # A tibble: 2 × 4
#> spct.idx lon lat address
#> <chr> <dbl> <dbl> <chr>
#> 1 A 10 30 North
#> 2 B -10 -30 South
