Convert an object of class prevR into a data.frame.
Source:R/as.data.frame.prevR.r
as.data.frame.prevR.Rd
This function merges the slots clusters
et rings
of
a object of class prevR
.
Usage
# S3 method for class 'prevR'
as.data.frame(x, ..., N = NULL, R = NULL, clusters.only = FALSE)
Arguments
- x
object of class
prevR
.- ...
not used, for compatibility with the generic method
base::as.data.frame()
.- N
integer or list of integers setting elements of
rings
to extract.- R
integer or list of integers setting elements of
rings
to extract.- clusters.only
return only the slot
clusters
ofx
?
Value
If clusters.only = TRUE
, the function will return only the
slot clusters
of x
.
Otherwise, slots clusters
and rings
of x
will be
merged in a unique data frame. The columns of rings
will be renamed
adding a suffix like .N300.RInf.
N
and R
define the elements of rings
to extract.
If not specified (NULL
), all the elements of rings
will
be included.
Examples
str(fdhs)
#> Formal class 'prevR' [package "prevR"] with 4 slots
#> ..@ clusters:'data.frame': 401 obs. of 10 variables:
#> .. ..$ id : int [1:401] 1 10 100 101 102 103 104 105 106 107 ...
#> .. ..$ x : num [1:401] -1.21 -1.79 -2.29 -2.71 -1.96 ...
#> .. ..$ y : num [1:401] 7.29 6.13 5.96 6.04 5.12 ...
#> .. ..$ n : num [1:401] 23 22 22 28 21 21 11 24 23 15 ...
#> .. ..$ pos : num [1:401] 0 0 0 0 3 4 0 1 0 0 ...
#> .. ..$ c.type: Factor w/ 2 levels "Rural","Urban": 1 1 1 1 1 1 1 1 1 1 ...
#> .. ..$ wn : num [1:401] 19.8 19.8 20.2 20.2 20.2 ...
#> .. ..$ wpos : num [1:401] 0 0 0 0 2.88 ...
#> .. ..$ prev : num [1:401] 0 0 0 0 14.3 ...
#> .. ..$ wprev : num [1:401] 0 0 0 0 14.3 ...
#> ..@ boundary:Classes ‘sf’ and 'data.frame': 1 obs. of 1 variable:
#> .. ..$ geometry:sfc_POLYGON of length 1; first list element: List of 1
#> .. .. ..$ : num [1:4056, 1:2] 1.28 1.25 1.23 1.22 1.22 ...
#> .. .. ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
#> .. ..- attr(*, "sf_column")= chr "geometry"
#> .. ..- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..:
#> .. .. ..- attr(*, "names")= chr(0)
#> .. ..- attr(*, "valid")= logi TRUE
#> ..@ proj :List of 2
#> .. ..$ input: chr "+proj=longlat +datum=WGS84"
#> .. ..$ wkt : chr "GEOGCRS[\"unknown\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.25722"| __truncated__
#> .. ..- attr(*, "class")= chr "crs"
#> ..@ rings : list()
str(as.data.frame(fdhs))
#> 'data.frame': 401 obs. of 10 variables:
#> $ id : int 1 10 100 101 102 103 104 105 106 107 ...
#> $ x : num -1.21 -1.79 -2.29 -2.71 -1.96 ...
#> $ y : num 7.29 6.13 5.96 6.04 5.12 ...
#> $ n : num 23 22 22 28 21 21 11 24 23 15 ...
#> $ pos : num 0 0 0 0 3 4 0 1 0 0 ...
#> $ c.type: Factor w/ 2 levels "Rural","Urban": 1 1 1 1 1 1 1 1 1 1 ...
#> $ wn : num 19.8 19.8 20.2 20.2 20.2 ...
#> $ wpos : num 0 0 0 0 2.88 ...
#> $ prev : num 0 0 0 0 14.3 ...
#> $ wprev : num 0 0 0 0 14.3 ...
if (FALSE) { # \dontrun{
r.fdhs <- rings(fdhs, N = c(100, 200, 300))
str(r.fdhs)
str(as.data.frame(r.fdhs, clusters.only = TRUE))
str(as.data.frame(r.fdhs))
str(as.data.frame(r.fdhs, N = 300))
} # }