Description Usage Arguments Details Value Warning See Also Examples
Convert a DemographicArray
object to a data frame.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## S4 method for signature 'Counts'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
responseName = "count",
direction = c("long", "wide"),
midpoints = FALSE,
...
)
## S4 method for signature 'Values'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
stringsAsFactors = FALSE,
responseName = "value",
direction = c("long", "wide"),
midpoints = FALSE,
...
)
|
x |
Object of class |
row.names |
'NULL' or a character vector giving the row names for the
data frame. See |
optional |
Logical. See |
stringsAsFactors |
Logical. If |
responseName |
Name of column with numeric values when |
direction |
Character. Whether data are converted to
|
midpoints |
|
... |
Additional arguments to be passed to or from methods. |
If direction
is "long"
, then
object
is put into "long" format, with a column to represent each
dimension, plus a final column holding the data. The final column is called
"count"
if object
has class Counts
and
"value"
if object
has class Counts
.
If direction
is "wide"
, then object
is flattened into a
matrix before conversion to a data frame, which is what the method for
ordinary arrays does.
If midpoints
is FALSE
, interval labels are converted into
factors. If midpoints
is TRUE
, interval labels are replaced
by numbers giving their midpoints. If names of individual dimensions are
supplied, then only the named dimensions are converted.
A data frame.
By default, the as.data.frame
methods for demographic arrays
convert the arrays to long format, since this is almost always what
is wanted. This is different from the as.data.frame
method for ordinary arrays in the base
package, which always
converts to wide format.
as.data.frame
,
as.data.frame.table
, data.frame
,
midpoints
1 2 3 4 5 6 7 8 9 10 11 12 | library(demdata)
popn <- Counts(VAPopn)
as.data.frame(popn)
as.data.frame(popn, direction = "wide")
x <- Values(array(1:4,
dim = c(2, 2),
dimnames = list(age = c("0-39", "40+"),
period = c("2001-2010", "2011-2020"))))
as.data.frame(x)
as.data.frame(x, midpoints = TRUE)
as.data.frame(x, midpoints = "period")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.