将标记 (S3:data.frame) 转换为具有水平的因子

Convert marks (S3:data.frame) to factors with levels

关于这个 我有一个 sptatstat ppp 对象 sf_owin 它有 marks 作为 S3:data.frame 如下所示:

sf_object 看起来像这样:

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

如何将标记从 S3:data.frame 转换为具有三个级别 (COOP_ID, STATION_NA and Annual_Precipitation)factor?或者我认为只 drop/remove COOP_IDAnnual_Precipitation 会更好,因为我真的不需要它们来完成特定任务。

加载 spatstat 并将 ppp 对象保存为 sf_owinppp 对象的名称非常违反直觉),您可以简单地将标记覆盖为:

marks(sf_owin) <- factor(marks(sf_owin)$STATION_NA)

此处省略降水等信息