Skip to contents

Validates and creates a valid crossmap xmap_df object.

This function returns TRUE for crossmaps xmap or subclasses thereof (xmap_df), and FALSE for all other objects, including regular data.frames or tibbles.

Usage

as_xmap_df(
  x,
  from,
  to,
  weights,
  tol = .Machine$double.eps^0.5,
  subclass = c("xmap_df"),
  ...
)

# S3 method for data.frame
as_xmap_df(
  x,
  from,
  to,
  weights,
  tol = .Machine$double.eps^0.5,
  subclass = "xmap_df",
  .drop_extra = NULL
)

is_xmap(x)

is_xmap_df(x)

Arguments

x
  • For as_xmap_df(): An object to coerce

  • For is_xmap_df(): An object to test.

from, to

Columns in x specifying the source and target nodes

weights

Column in x specifying the weight applied to data passed along the directed link between source and target node

tol

numeric \(\ge 0\). Ignore differences smaller than tol. Passed through to the tolerance arg of base::all.equal().

subclass

Which xmap subclass to return. Defaults to xmap_df for data.frame and tibble

.drop_extra

Drop columns other than from, to and weights. Defaults to TRUE

Value

A validated xmap object.

Functions

  • as_xmap_df(data.frame): Coerce a data.frame to xmap

Examples

# For a well formed crossmap:
links <- data.frame(
  a = "AUS",
  b = c("VIC", "NSW", "WA", "OTHER"),
  w = c(0.1, 0.15, 0.25, 0.5)
)
as_xmap_df(links, from = a, to = b, weights = w)
#> Dropping any additional columns in `links`
#>  To silence set `.drop_extra = TRUE`
#> xmap_df:
#> split 
#> (a -> b) BY w
#>     a     b    w
#> 1 AUS   VIC 0.10
#> 2 AUS   NSW 0.15
#> 3 AUS    WA 0.25
#> 4 AUS OTHER 0.50

# extra columns are dropped,
links$extra <- c(2, 4, 5, 6)
as_xmap_df(links, from = a, to = b, weights = w)
#> Dropping any additional columns in `links`
#>  To silence set `.drop_extra = TRUE`
#> xmap_df:
#> split 
#> (a -> b) BY w
#>     a     b    w
#> 1 AUS   VIC 0.10
#> 2 AUS   NSW 0.15
#> 3 AUS    WA 0.25
#> 4 AUS OTHER 0.50