View source: R/assign_treated.R
assign_treated | R Documentation |
Creates a vector with 0's and 1's to determine on which side of the cut-off each observation is. For this it is useful to have a polygon that fully describes the "treated area".
If you do not have such a polygon there is a (preliminary and patchy) way implemented in the package via points2line
and cutoff2polygon
that lets you go from points to line to "treated polygon" in a very crude way.
assign_treated(data, polygon, id = NA)
data |
sf data frame containing point data (if you have polygons, convert first with sf::st_centroid()) |
polygon |
sf object with polygon geometry that fully describes the area(s) that contain the treated points |
id |
string that represents the name of the column in the data that represents the unique identifier for each observation |
A vector of type factor with 0's and 1's. Convert with as.numeric() if you want real numbers/integers.
This is essentially a wrapper of sf::st_intersection
.
points_samp.sf <- sf::st_sample(polygon_full, 100) # create points
# make it an sf object bc st_sample only created the geometry list-column (sfc):
points_samp.sf <- sf::st_sf(points_samp.sf)
# add a unique ID to each observation:
points_samp.sf$id <- 1:nrow(points_samp.sf)
points_samp.sf$treated <- assign_treated(points_samp.sf, polygon_treated, id = "id")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.