1 | long2mat(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 | ##---- 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 (length(dep.col) != 1)
stop("Argument dep.col must have a single value")
if (is.null(dim(x)))
stop("x must be a matrix or data frame")
Sid = unique(x[, Sid.col])
n = nrow(x)
nid = length(Sid)
flag = (x[, Sid.col] == Sid[1])
num.out = sum(flag)
res = matrix(NA, nrow = nid, ncol = num.out)
for (i in 1:nid) {
flag = (x[, Sid.col] == Sid[i])
res[i, ] = x[flag, dep.col]
}
res
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.