fac.split {dae}R Documentation

Splits a factor whose levels consist of several delimited strings into several factors

Description

Splits a factor, whose levels consist of strings delimited by a separator character, into several factors. It uses the function strsplit, with fixed = TRUE to split the levels.

Usage

fac.split(combined.factor, factor.names, sep=",", ...)

Arguments

combined.factor

A factor to be split into several factors.

factor.names

A list of names for factors and associated levels, if required. The names of the components of the list are used for the names of the new factors. Each component of the list should either be NULL or a vector of levels for the new factor. If a component is NULL then the unique values for the supplied factor are used as the levels, which are sorted into alphabetical order. If a either a numeric or a character vector is supplied for a component, then these are supplied as the levels of the new factor.

sep

A character string that separates the levels in the combined.factor.

...

Further arguments passed to the factor call creating the new factor.

Value

A data.frame containing the new factors.

Author(s)

Chris Brien

See Also

fac.divide, fac.uncombine, fac.combine in package dae and strsplit.

Examples

## Form a combined factor to split
data(Oats.dat)
tmp <- within(Oats.dat, Trts <- fac.combine(list(Variety, Nitrogen), combine.levels = TRUE))

##Variety levels sorted into alphabetical order
trts.dat <- fac.split(combined.factor = tmp$Trts, 
                      factor.names = list(Variety = NULL, Nitrogen = NULL))

##Variety levels order from Oats.dat retained
trts.dat <- fac.split(combined.factor = tmp$Trts, 
                      factor.names = list(Variety = levels(tmp$Variety), Nitrogen = NULL))

[Package dae version 3.2.28 Index]