Learn R Programming

SunCalcMeeus (version 0.1.3)

split_geocodes: Split or bind geocodes

Description

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")

Value

A list of geo_code data frames or a single geocode data frame.

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

Run this code
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)
split_geocodes(my.geocodes[1, ])

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)

Run the code above in your browser using DataLab