The ssn_put_data
function puts an sf
data.frame representing observation or prediction
data into an SSN, ssn_lm, or ssn_glm object.
Arguments
- data
sf data.frame with point geometry.
- x
An object of class SSN, ssn_lm, or ssn_glm.
- name
the internal name of the data set in the object
x
. For observed data, this will always be "obs", the default.- resize_data
Logical. Indicates whether sf_df can have a different number of features than the current data.frame in the object. Default is FALSE.
Details
The internal name
for observed data in objects of
class SSN
, ssn_lm
, and ssn_glm
is "obs" and it is the
default. If another name
is specified, it must represent a
prediction dataset in the object. For SSN
objects,
these names are obtained using the call names(x$preds)
. For
all other object classes, the names are obtained using the call
names(x$ssn.object$preds).
The resize_sf_data
argument specifies whether sf_data can have a
different number of features (i.e., rows) than the sf data.frame
it is replacing. Care should be taken when resize_df is set to
TRUE, especially if the new sf_data has more features than the
existing sf data.frame. In these cases, the user is responsible
for ensuring that the additional features have the correct
spatial, topological, and attribute data to accurately represent
spatial relationships in the SSN object.
Examples
data(mf04p)
## Extract observation data.frame from SSN object
obs.df <- ssn_get_data(mf04p)
## Create a new column for summer mean temperature and set Value in
obs.df$Value <- obs.df$Summer_mn
obs.df$Value[1] <- NA
## Put the modified sf data.frame into the SSN object
mf04p <- ssn_put_data(obs.df, mf04p)
head(ssn_get_data(mf04p)[, c("Summer_mn", "Value")])
#> Simple feature collection with 6 features and 2 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -1515032 ymin: 2529461 xmax: -1512690 ymax: 2531883
#> Projected CRS: USA_Contiguous_Albers_Equal_Area_Conic_USGS_version
#> Summer_mn Value geometry
#> 1 11.38 NA POINT (-1512690 2531883)
#> 2 10.72 10.72 POINT (-1512852 2531295)
#> 3 10.43 10.43 POINT (-1513400 2530706)
#> 4 10.13 10.13 POINT (-1514027 2530147)
#> 5 10.12 10.12 POINT (-1514309 2529902)
#> 6 9.81 9.81 POINT (-1515032 2529461)