The ssn_put_data function puts an sf data.frame representing observation or prediction data into an SSN, ssn_lm, or ssn_glm object.

ssn_put_data(data, x, name = "obs", resize_data = FALSE)

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.

Value

Returns an object of the same class as x, which contains the sf data.frame sf_data.

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.

See also

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: -1528485 ymin: 927846.1 xmax: -1519790 ymax: 930808.7
#> Projected CRS: USA_Contiguous_Albers_Equal_Area_Conic
#>   Summer_mn Value                  geometry
#> 1     14.92    NA POINT (-1528194 929550.4)
#> 2     14.72 14.72 POINT (-1528222 928237.7)
#> 3     14.61 14.61 POINT (-1528485 927846.1)
#> 4     15.22 15.22 POINT (-1519790 930112.1)
#> 5     14.49 14.49   POINT (-1520336 929772)
#> 6     15.29 15.29 POINT (-1524599 930808.7)