as.folder.folderh: Hierarchic folder to folder

View source: R/as.folder.folderh.R

as.folder.folderhR Documentation

Hierarchic folder to folder

Description

Creates an object of class folder, that is a list of data frames with the same column names, from a folderh.

Usage

## S3 method for class 'folderh'
as.folder(x, elt = names(x)[2], key = attr(x, "keys")[1], ...)

Arguments

x

object of class folderh containing N (N>1) data frames: x[[1]],..., x[[N]], related by (N-1) keys: keys[1],..., keys[N-1].

elt

string. The name of one element of x, that is data frame, say the j-th, whose rows are distributed among the data frames of the returned folder. See details.

key

string. The name of an element of attr(x, "keys"), that is the key, say the k-th with k<j, which is the factor whose levels are the names of the data frames of the returned folder. See details.

...

further arguments passed to or from other methods.

Value

as.folder.folderh returns an object of class folder, a list of data frames with the same columns. These data frames contain the values of x[[elt]] (or x[[j]]) and the corresponding values of the data frames x[[j-1]], ... x[[k]], these correspondances being defined by the keys of the hierarchic folder. The names of these data frames are given by the levels of the key attr(x, "keys")[k]).

The rows of the data frame x[[elt]] (or x[[j]]) are distributed among the data frames of the returned folder accordingly to the levels of the key attr(x, "keys")[k]. So the row names of the l-th data frame of the returned folder consist in the rows of x[[j]] corresponding to the l-th level of the key attr(x, "keys")[k].

The column names of the data frames of the returned folder are the union of the column names of the data frames x[[k]],..., x[[j]] and are organized in two parts.

  1. The first part consists in the columns of x[[k]] except the column corresponding to the key attr(x, "keys")[k].

  2. For each i=k+1,...,j the column names of the data frame x[[i]] are reorganized so that the key attr(x, "keys")[i] is its first column. The columns of the reorganized data frames x[[k+1]],..., x[[j]] are concatenated. The result forms the second part.

Notice that if:

  • the folderh has two data frames df1 and df2, where the factor corresponding to the key has T levels, and one column of df2, say df2[, "Fa"], is a factor with levels "a1", ..., "ap"

  • and the folder returned by as.folder includes T data frames dat1, ..., datT,

then each of dat1, ..., datT has a column named "Fa" which is a factor with the same levels "a1", ..., "ap" as df2[, "Fa"].

Author(s)

Rachid Boumaza, Pierre Santagostini, Smail Yousfi, Gilles Hunault, Sabine Demotes-Mainard

See Also

folder, folderh. as.folder.folderh to build an object of class folder from an object of class folderh. as.data.frame.folder to build a data frame from an object of class folder. as.data.frame.folderh to build a data frame from an object of class folderh.

Examples

# First example: flowers               
data(roseflowers)
flg <- roseflowers$variety
flx <- roseflowers$flower

flfh <- folderh(flg, "rose", flx)
print(flfh)

flf <- as.folder(flfh)
print(flf)

# Second example: castles               
data(castles.dated)
cag <- castles.dated$periods
cax <- castles.dated$stones

cafh <- folderh(cag, "castle", cax)
print(cafh)

caf <- as.folder(cafh)
print(caf)

# Third example: leaves (example of a folderh of more than two data frames)
data(roseleaves)
lvr <- roseleaves$rose
lvs <- roseleaves$stem
lvl <- roseleaves$leaf
lvll <- roseleaves$leaflet

lfh <- folderh(lvr, "rose", lvs, "stem", lvl, "leaf", lvll)

lf1 <- as.folder(lfh, elt = "lvs", key = "rose")
print(lf1)

lf2 <- as.folder(lfh, elt = "lvl", key = "rose")
print(lf2)

lf3 <- as.folder(lfh, elt = "lvll", key = "rose")
print(lf3)

lf4 <- as.folder(lfh, elt = "lvll", key = "stem")
print(lf4)

dad documentation built on Aug. 30, 2023, 5:06 p.m.