as.data.frame.folderh: Hierarchic folder to data frame

View source: R/as.data.frame.folderh.R

as.data.frame.folderhR Documentation

Hierarchic folder to data frame

Description

Builds a data frame from a folderh.

Usage

## S3 method for class 'folderh'
as.data.frame(x, row.names = NULL, optional = FALSE, ...,
        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].

row.names, optional

for consistency with as.data.frame. Not taken into account.

...

further arguments passed to or from other methods.

elt

string. The name of one element of x, that is the data frame, say the j-th, whose rows are the rows of the returned data frame. 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 designating the last column of the returned data frame. See details.

Value

as.data.frame.folderh returns a data frame whose row names are those of x[[elt]] (that is x[[j]]). The data frame contains the values of x[[elt]] and the corresponding values of the data frames x[[k]], these correspondances being defined by the keys of the hierarchic folder.

The column names of the returned data frame are organized in three parts.

  1. The first part consists in the key names keys[k],..., keys[j-1].

  2. The second part consists in the values of x[[j]].

  3. The third part consists in the values of x[[k]] except the key keys[k].

See the examples to view these details.

Author(s)

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

See Also

folder, folderh, as.folder.folderh.

Examples

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

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

fldf <- as.data.frame(flfh)
print(fldf)

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

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

cadf <- as.data.frame(cafh)
print(summary(cadf))

# Third example: leaves (example of a folderh with 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.data.frame(lfh, elt = "lvs", key = "rose")
print(lf1)

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

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

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

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