Create a cubble object
Usage
cubble(..., key, index, coords)
make_cubble(
spatial,
temporal,
by = NULL,
key,
index,
coords,
potential_match = NULL,
key_use = "temporal"
)Arguments
- ...
a set of name-value pairs to create a cubble, need to include the
key,index, andcoordsvariables.- key
a character (or symbol), the spatial identifier. See the Key section in
tsibble::as_tsibble()- index
a character (or symbol), the temporal identifier. Currently support base R classes
Date,POSIXlt,POSIXctand tsibble'stsibble::yearmonth(),tsibble::yearweek(), andtsibble::yearquarter()class. See the Index section intsibble::as_tsibble()- coords
a vector of character (or symbol) of length two, in the order of longitude first and then latitude, the argument can be omitted if created from an sf and its subclasses. In case the sf geometry column is not POINT, coords will be the centroid coordinates.
- spatial
a tibble object or an sf object, the spatial component containing the
keyandcoordsvariable (coordscan be automatically created from ansfobject if not supplied).- temporal
a tibble object or a tsibble object, the temporal component containing the
keyandindexvariable.- by
in the syntax of the
byargument indplyr::left_join(), used inmake_cubble()when the key variable has different names in thespatialandtemporaldata.- potential_match
a
key_tblobject fromcheck_key(). When unmatched key values appear in spatial and temporal data,make_cubblewill prompt the user to usecheck_key()for checking. This argument allow the check result to be parsed back tomake_cubbleto also match thepotential_pairsfound by the check.- key_use
a character of either "spatial" or "temporal". When
potential_mathis activated, this argument specifies which key column in the potential match to use. Default to "temporal".
Examples
cubble(
id = rep(c("perth", "melbourne", "sydney"), each = 3),
date = rep(as.Date("2020-01-01") + 0:2, times = 3),
long = rep(c(115.86, 144.96, 151.21), each = 3),
lat = rep(c(-31.95, -37.81, -33.87), each = 3),
value = rnorm(n = 9),
key = id, index = date, coords = c(long, lat)
)
#> # cubble: key: id [3], index: date, nested form
#> # spatial: [115.86, -37.81, 151.21, -31.95], Missing CRS!
#> # temporal: date [date], value [dbl]
#> id long lat ts
#> <chr> <dbl> <dbl> <list>
#> 1 perth 116. -32.0 <tibble [3 × 2]>
#> 2 melbourne 145. -37.8 <tibble [3 × 2]>
#> 3 sydney 151. -33.9 <tibble [3 × 2]>
# stations and climate are in-built data in cubble
make_cubble(spatial = stations, temporal = meteo,
key = id, index = date, coords = c(long, lat))
#> # cubble: key: id [3], index: date, nested form
#> # spatial: [144.83, -37.98, 145.1, -37.67], Missing CRS!
#> # temporal: date [date], prcp [dbl], tmax [dbl], tmin [dbl]
#> id long lat elev name wmo_id ts
#> <chr> <dbl> <dbl> <dbl> <chr> <dbl> <list>
#> 1 ASN00086038 145. -37.7 78.4 essendon airport 95866 <tibble [10 × 4]>
#> 2 ASN00086077 145. -38.0 12.1 moorabbin airport 94870 <tibble [10 × 4]>
#> 3 ASN00086282 145. -37.7 113. melbourne airport 94866 <tibble [10 × 4]>