Reshapes long, unit-keyed data into a unit-by-observation matrix and measures the distance between its rows.

scale_distance(
  data,
  x,
  frame = NULL,
  key = NULL,
  value = NULL,
  method = "euclidean",
  scale_units = FALSE
)

Arguments

data

Long data: a column of unit codes, one or more identifier columns saying which observation each row is, and a value column.

x

A NestedScale.

frame

Frame whose units are compared. Defaults to the atom frame.

key

Column of data holding the unit codes. Defaults to frame when present, else the scale's key.

value

Value column; inferred when unambiguous.

method

A name from list_scale_distances().

scale_units

Standardise each unit's profile to mean 0, sd 1 before measuring. Turns a level distance into a shape distance; has no effect on "correlation", which already ignores level.

Value

A stats::dist object over the frame's units, in member order.

Examples

s <- scale_example()
d <- data.frame(
  unit = rep(scale_units(s), each = 3),
  t = rep(sprintf("t%d", 1:3), 7), v = as.numeric(seq_len(21))
)
round(scale_distance(d, s, method = "correlation"), 2)
#>     U1 U2 U3 U4 U5 U6
#> U2   0               
#> U3   0  0            
#> U4   0  0  0         
#> U5   0  0  0  0      
#> U6   0  0  0  0  0   
#> OTH  0  0  0  0  0  0