Description Usage Arguments Details Value Note See Also Examples
Cast a list of molten (i.e. long-format) (i.e. database-like) data frames into a data list.
1 |
x |
A list of long-format data frames |
dimids |
See |
fill |
A vector the same |
placeholders |
Character vector giving elements of the |
... |
Additional arguments to pass to |
This is one of several ways to create data.list
objects. It is useful when the data are stored as several long-format data.frame
objects. For the purposes of dlcast
, a long-format data frame is a data frame with one named column for each variable, one named column for each dimension of replication (called idvar
s in the reshape2
package), and one row for each (possibly multivariate) sample. Several data frames will allow variables to differ in their dimensions of replication. In order to combine several data frames into a valid data list, at least one data frame must contain all of the dimensions of replication in all of the data frames. Each data frame column that corresponds to a dimension of replication must be coercible to factor
.
A data list.
This function is inspired by the acast
function in the reshape2
package by Hadley Wickham. Levi Waldron was a great help during the writing of dlcast
. The placeholders
argument arose out of a suggestion of a reviewer.
For other ways to create data.list
objects: data.list
; as.data.list
; read.multitable
; variable
.
For an approximate inverse of dlcast
, see dlmelt
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ## a fictitious data set with a fourth-corner problem
abundance <- data.frame(
sites=c(
"midlatitude", "subtropical", "tropical", "equatorial",
"arctic", "midlatitude", "tropical", "equatorial",
"subtropical"
),
species=c(rep("capybara", 4), rep("moss", 4), "vampire"),
abundance=c(4, 10, 8, 7, 5, 6, 9, 3, 1)
)
environment <- data.frame(
sites=c(
"arctic", "subarctic", "midlatitude", "subtropical",
"tropical", "equatorial"
),
temperature=c(-30, 0, 10, 20, 50, 30),
precipitation=c(20, 40, 20, 100, 150, 200)
)
trait <- data.frame(
species=c("capybara", "moss", "vampire"),
body.size=c(140, 5, 190),
metabolic.rate=c(20, 5, 0)
)
dlcast(list(abundance, environment, trait),
dimids=c("sites", "species"),
fill=c(0, NA, NA)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.