View source: R/as.folder.folderh.R
as.folder.folderh | R Documentation |
Creates an object of class folder
, that is a list of data frames with the same column names, from a folderh
.
## S3 method for class 'folderh'
as.folder(x, elt = names(x)[2], key = attr(x, "keys")[1], ...)
x |
object of class |
elt |
string. The name of one element of |
key |
string. The name of an element of |
... |
further arguments passed to or from other methods. |
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.
The first part consists in the columns of x[[k]]
except the column corresponding to the key attr(x, "keys")[k]
.
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"]
.
Rachid Boumaza, Pierre Santagostini, Smail Yousfi, Gilles Hunault, Sabine Demotes-Mainard
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
.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.