folderh function

Hierarchic folder of n data frames related in pairs by (n-1) keys

Hierarchic folder of n data frames related in pairs by (n-1) keys

Creates an object of class folderh, that is a list of n>1n>1 data frames whose rows are related by (n-1) keys, each key defining a relation "1 to N" between the two adjacent data frames passed as arguments of the function.

folderh(df1, key1, df2, ..., na.rm = TRUE)

Arguments

  • df1: data frame (can also be a tibble) with at least two columns. It contains a factor (whose name is given by key1 argument) whose levels are taken exactly once.
  • key1: character string. The name of the factor of the data frames df1 and df2 which contains the key of the relations "1 to N" between the two datasets.
  • df2: data frame (or tibble) with at least two columns. It contains a factor column (named by keys argument) with the same levels as df1[, key1] (see Details).
  • ...: optional. One or several supplementary character strings and data frames, ordered as follows: key2, df3, .... The argument key2 indicates the key defining the relation "1 to N" between the data frames df2 and df3, and so on.
  • na.rm: logical. If TRUE, the rows of each data frame for which the key is NA are removed.

Returns

Returns an object of class folderh. Its elements are the data frames passed as arguments, and the attribute attr(, "keys") contains the character arguments.

Details

The object of class folderh is a list of n2n \ge 2 data frames.

  • If no optional arguments are given via ..., that is n=2n = 2, the two data frames of the list have a column named by the attribute attr(, "keys") (argument key1), which is a factor with the same levels. Each one of these levels occur exactly once in the first data frame of the list.
  • If some supplementary data frames and supplementary strings key2, df3, ... are given as optional arguments, nn is the number of data frames given as arguments. Then, the attribute attr(, "keys") is a vector of n1n-1 character strings. For i=1,,N1i = 1, \ldots, N-1, its ii-th element is the name of a column of the ii-th and (i+1)(i+1)-th data frames of the folderh, which are factors with the same levels. Each one of these levels occur exactly once in the ii-th data frame.

If there are more than two data frames, folderh computes a folderh with the two last data frames, and then uses the function appendtofolderh to append each one of the other data frames to the folderh.

Author(s)

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

See Also

is.folderh to test if an object is of class folderh. folder for a folder of data frames with no hierarchic relation between them. as.folder.folderh (or as.data.frame.folderh) to build an object of class folder (or a data frame) from an object of class folderh,

Examples

# First example: rose flowers data(roseflowers) df1 <- roseflowers$variety df2 <- roseflowers$flower fh1 <- folderh(df1, "rose", df2) print(fh1) # Second example data(roseleaves) roses <- roseleaves$rose stems <- roseleaves$stem leaves <- roseleaves$leaf leaflets <- roseleaves$leaflet fh2 <- folderh(roses, "rose", stems, "stem", leaves, "leaf", leaflets) print(fh2)
  • Maintainer: Pierre Santagostini
  • License: GPL (>= 2)
  • Last published: 2024-11-22