dlcast: Cast data lists

Description Usage Arguments Details Value Note See Also Examples

Description

Cast a list of molten (i.e. long-format) (i.e. database-like) data frames into a data list.

Usage

1
dlcast(x, dimids, fill, placeholders, ...)

Arguments

x

A list of long-format data frames

dimids

See data.list. If missing, a reasonable guess is made, which is the column names shared by all data frames in x.

fill

A vector the same length as x, giving the value to use for structural missing values for each of the data frames in x.

placeholders

Character vector giving elements of the dimids columns that are to be omitted.

...

Additional arguments to pass to as.data.list and data.list.

Details

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 idvars 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.

Value

A data list.

Note

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.

See Also

For other ways to create data.list objects: data.list; as.data.list; read.multitable; variable. For an approximate inverse of dlcast, see dlmelt.

Examples

 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)
)

stevencarlislewalker/multitable documentation built on May 30, 2019, 4:44 p.m.