get.crossdist: Get distance between two points for one observation

Description Usage Arguments Value Author(s) See Also Examples

View source: R/hmob_funcs.R

Description

Takes X and Y coordinates of two locations and returns cross distance for all entries.

Usage

1
get.crossdist(xy1, xy2, id1 = NULL, id2 = NULL)

Arguments

xy1

two column matrix of XY coordinates for first group

xy2

two column matrix of XY coordinates for second group

id1

optional names for first group

id2

optional names for second group

Value

numeric scalar or matrix

Author(s)

John Giles

See Also

Other data synthesis: calc.prop.tot.trips(), calc.route.type(), calc.samp.size(), get.distance.class(), get.distance.counts(), get.distance.matrix(), get.district.names.xy(), get.district.pop(), get.duration.counts(), get.holidays(), get.sparse.mob.matrix(), get.stay.data(), get.subsamp(), get.xy.counts(), mob.data.array(), parse.longform()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Some XY coords in decimal degrees
xy1 <- data.frame(x=rnorm(3, 100, 1), 
                 y=rnorm(3, 20, 1),
                 id=LETTERS[1:3])

xy2 <- data.frame(x=rnorm(5, 100, 1), 
                 y=rnorm(5, 20, 1),
                 id=LETTERS[4:8])

D <- get.crossdist(xy1=xy1[,1:2],
                   xy2=xy2[,1:2],
                   id1=xy1[,3],
                   id2=xy2[,3])

D
D*111.35 # in km


# Overlapping sets of coordinates
xy1 <- data.frame(x=rnorm(3, 100, 1), 
                  y=rnorm(3, 20, 1),
                  id=LETTERS[1:3])

xy2 <- rbind(xy1,
             data.frame(x=rnorm(5, 100, 1), 
                        y=rnorm(5, 20, 1),
                        id=LETTERS[4:8]))

D <- get.crossdist(xy1=xy1[,1:2],
                   xy2=xy2[,1:2],
                   id1=xy1[,3],
                   id2=xy2[,3])

D
D*111.35 # in km

gilesjohnr/hmob documentation built on Aug. 8, 2020, 1:26 a.m.