1 | longcov2mat(x, Sid.col, dep.col)
|
x |
|
Sid.col |
|
dep.col |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (x, Sid.col, dep.col)
{
if (is.null(dim(x)))
stop("x must be a matrix or data frame")
Sid = unique(x[, Sid.col])
res = list()
nid = length(Sid)
p = length(dep.col)
n = nrow(x)
flag = (x[, Sid.col] == Sid[1])
n.each.s = sum(flag)
ns = n/n.each.s
if (!is.wholenumber(ns))
stop("Not all S's have same number of rows of data")
for (i in 1:ns) {
flag = (x[, Sid.col] == Sid[i])
res[[i]] = as.matrix(x[flag, dep.col])
}
res
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.