sf (version 0.5-2)

st_join: spatial left or inner join

Description

spatial left or inner join

Usage

st_join(x, y, join = st_intersects, FUN, suffix = c(".x", ".y"),
  prepared = TRUE, left = TRUE, ...)

Arguments

x

object of class sf

y

object of class sf

join

geometry predicate function with the same profile as st_intersects; see details

FUN

deprecated;

suffix

length 2 character vector; see merge

prepared

logical; see st_intersects

left

logical; if TRUE carry out left join, else inner join; see also left_join

...

arguments passed on to the join function (e.g. a pattern for st_relate)

Value

an object of class sf, joined based on geometry

Details

alternative values for argument join are: st_disjoint st_touches st_crosses st_within st_contains st_overlaps st_covers st_covered_by st_equals or st_equals_exact, or user-defined functions of the same profile

Examples

Run this code
# NOT RUN {
a = st_sf(a = 1:3,
 geom = st_sfc(st_point(c(1,1)), st_point(c(2,2)), st_point(c(3,3))))
b = st_sf(a = 11:14,
 geom = st_sfc(st_point(c(10,10)), st_point(c(2,2)), st_point(c(2,2)), st_point(c(3,3))))
st_join(a, b)
st_join(a, b, left = FALSE)
# two ways to aggregate y's attribute values outcome over x's geometries:
st_join(a, b) %>% aggregate(list(.$a.x), mean)
library(dplyr)
st_join(a, b) %>% group_by(a.x) %>% summarise(mean(a.y))
# }

Run the code above in your browser using DataLab