cast2zoocat: Cast a data frame to a 'zoocat' object

Description Usage Arguments Value Examples

Description

Cast a data frame to a "zoocat" object. The data frame should be a long format data frame (for example, melted by reshape2::melt).

Usage

1
2
cast2zoocat(x, index.var, value.var, attr.var = NULL, fun.aggregate = NULL,
  del.unique.cattr = TRUE)

Arguments

x

a data frame.

index.var

the name of the column to be treated as the index of the zoocat object.

value.var

the name of the column which stored the values.

attr.var

the name of the column which will be used as column attributes of the zoocat object. If NULL, all columns except value.var and index.var will be used.

fun.aggregate

aggregation function needed if variables do not identify a single observation for each output cell. Defaults to length (with a message) if needed but not specified. See dcast.

del.unique.cattr

logical. If TRUE, the column attibutes with unique value will be deleted.

Value

a "zoocat" object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
df <- data.frame(year = rep(1991 : 1995, each = 24), month = rep(1 : 12, 10),
                 varname = rep(c('a', 'b'), each = 12), city = rep(1 : 3, each = 40),
                 value = 1 : 120)
cast2zoocat(df, index.var = 'year', value.var = 'value')
cast2zoocat(df, index.var = 'year', value.var = 'value', attr.var = 'varname')

## This is the air quality example from package reshape2
names(airquality) <- tolower(names(airquality))
aqm <- melt(airquality, id = c("month", "day"), na.rm=TRUE) 
head(aqm)
cast2zoocat(aqm, index.var = 'month', value.var = 'value', attr.var = 'variable')
cast2zoocat(aqm, index.var = 'month', value.var = 'value')

ran-ran/zoocat documentation built on May 26, 2019, 10:56 p.m.