In relation to this question I have a sptatstat ppp
object sf_owin
which has marks
as S3:data.frame
as seen below:
The sf_object looks like this:
Simple feature collection with 131 features and 3 fields
geometry type: MULTIPOINT
dimension: XY
bbox: xmin: -1932934 ymin: 4958872 xmax: -1439558 ymax: 5861173
projected CRS: NAD83(2011) / UTM zone 16N
# A tibble: 131 x 4
# Groups: COOPID [131]
COOPID STATION_NA geometry Annual_Precipitation
* <dbl> <chr> <MULTIPOINT [m]> <dbl>
1 0 Ontario ((-1899685 5335073)) 9.24
2 100010 ABERDEEN EXPERIMNT STN ((-1610453 5091311)) 12.4
3 100227 AMERICAN FALLS 3 NW ((-1623401 5075011)) 20.4
4 100282 ANDERSON DAM ((-1807106 5212322)) 16.3
5 100347 ARBON 2 NW ((-1606302 5034484)) 10.2
6 100375 ARCO ((-1622855 5179969)) 19.5
7 100448 ARROWROCK DAM ((-1834338 5254236)) 20.1
8 100470 ASHTON ((-1458491 5179214)) 37.5
9 100528 AVERY RS #2 ((-1678382 5654084)) 25.3
10 100667 BAYVIEW MODEL BASIN ((-1691954 5753129)) 9.69
How can I convert marks from S3:data.frame to factor
with three levels (COOP_ID, STATION_NA and Annual_Precipitation)
? Or I think it would be better to just drop/remove COOP_ID
and Annual_Precipitation
as I don't really need them for the particular task.
With spatstat loaded and the ppp
object saved as sf_owin
(very counterintuitive name for a ppp
object) you can simply overwrite the marks as:
marks(sf_owin) <- factor(marks(sf_owin)$STATION_NA)
This omits the info about precipitation etc.