View source: R/as.foldert.data.frame.r
as.foldert.data.frame | R Documentation |
Builds an object of class foldert
from a data frame.
## S3 method for class 'data.frame'
as.foldert(x, method = 1, ind = 1, timecol = 2, nvar = NULL, same.rows = TRUE, ...)
x |
data frame. |
method |
1 or 2. Indicates the layout of the data frame x and, therefore, the method used to extract the data and build the foldert.
|
ind |
string or numeric. The name of the column of x containing the indentifiers of the measured objects, or the number of this column. |
timecol |
string or numeric.
|
nvar |
integer. If Omitted if |
same.rows |
logical. If Necessarily |
... |
further arguments passed to or from other methods. |
an object ft
of class foldert
, that is a list of data frames organised according to time; these data frames have the same column names.
If method = 1
, they can have the same row names (attr(ft, "same.rows") = TRUE
) or not (attr(ft, "same.rows") = FALSE
).
The time attribute attr(ft, "times")
has the same class as x[, timecol]
(numeric vector, ordered factor or object of class "Date"
, "POSIXlt"
or "POSIXct"
) and contains the values of x[, timecol]
.
If method = 2
, they necessarily have the same row names: attr(ft, "same.rows") = TRUE
and attr(ft, "times")
is 1:length(ft)
.
The rownames of each data frame are the identifiers of the individuals, as given by x[, ind]
.
Rachid Boumaza, Pierre Santagostini, Smail Yousfi, Gilles Hunault, Sabine Demotes-Mainard
foldert
: objects of class foldert
.
as.data.frame.foldert
: build a data frame from an object of class foldert
.
as.foldert.array
: build an object of class foldert
from a 3d
-array.
# First example: method = 1
times <- as.Date(c("2017-03-01", "2017-04-01", "2017-05-01"))
x1 <- data.frame(t=times[1], ind=1:6,
f=c("a","a","a","b","b","b"), z1=rep(0,6), z2=rep(0,6),
stringsAsFactors = TRUE)
x2 <- data.frame(t=times[2], ind=c(1,4,6),
f=c("a","b","b"), z1=rnorm(3,1,1), z2=rnorm(3,3,2),
stringsAsFactors = TRUE)
x3 <- data.frame(t=times[3], ind=c(1,3:6),
f=c("a","a","a","b","b"), z1=rnorm(5,3,2), z2=rnorm(5,6,3),
stringsAsFactors = TRUE)
x <- rbind(x1, x2, x3)
ft1 <- as.foldert(x, method = 1, ind = "ind", timecol = "t", same.rows = TRUE)
print(ft1)
ft2 <- as.foldert(x, method = 1, ind = "ind", timecol = "t", same.rows = FALSE)
print(ft2)
data(castles.dated)
periods <- castles.dated$periods
stones <- castles.dated$stones
stones$stone <- rownames(stones)
castledf <- merge(periods, stones, by = "castle")
castledf$period <- as.numeric(castledf$period)
castledf$stone <- as.factor(paste(as.character(castledf$castle),
as.character(castledf$stone), sep = "_"))
castfoldt1 <- as.foldert(castledf, method = 1, ind = "stone", timecol = "period",
same.rows = FALSE)
summary(castfoldt1)
# Second example: method = 2
times <- as.Date(c("2017-03-01", "2017-04-01", "2017-05-01"))
y1 <- data.frame(z1=rep(0,6), z2=rep(0,6))
y2 <- data.frame(z1=rnorm(6,1,1), z2=rnorm(6,3,2))
y3 <- data.frame(z1=rnorm(6,3,2), z2=rnorm(6,6,3))
y <- cbind(ind = 1:6, y1, y2, y3)
ft3 <- as.foldert(y, method = 2, ind = "ind", timecol = 2, nvar = 2)
print(ft3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.