1 |
m |
|
grpc |
|
coln |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | ##---- 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 (m, grpc, coln = NA)
{
if (is.na(coln))
stop("The argument coln is not specified")
if (length(grpc) > 4)
stop("The argument grpc must have length less than or equal to 4")
x <- vector("list")
ic <- 0
if (length(grpc) == 2) {
cat1 <- selby(m, grpc[1], coln)$grpn
cat2 <- selby(m, grpc[2], coln)$grpn
for (i1 in 1:length(cat1)) {
for (i2 in 1:length(cat2)) {
temp <- NA
it <- 0
for (i in 1:nrow(m)) {
if (sum(m[i, c(grpc[1], grpc[2])] == c(cat1[i1],
cat2[i2])) == 2) {
it <- it + 1
temp[it] <- m[i, coln]
}
}
if (!is.na(temp[1])) {
ic <- ic + 1
x[[ic]] <- temp
if (ic == 1)
grpn <- matrix(c(cat1[i1], cat2[i2]), 1,
2)
if (ic > 1)
grpn <- rbind(grpn, c(cat1[i1], cat2[i2]))
}
}
}
}
if (length(grpc) == 3) {
cat1 <- selby(m, grpc[1], coln)$grpn
cat2 <- selby(m, grpc[2], coln)$grpn
cat3 <- selby(m, grpc[3], coln)$grpn
x <- vector("list")
ic <- 0
for (i1 in 1:length(cat1)) {
for (i2 in 1:length(cat2)) {
for (i3 in 1:length(cat3)) {
temp <- NA
it <- 0
for (i in 1:nrow(m)) {
if (sum(m[i, c(grpc[1], grpc[2], grpc[3])] ==
c(cat1[i1], cat2[i2], cat3[i3])) == 3) {
it <- it + 1
temp[it] <- m[i, coln]
}
}
if (!is.na(temp[1])) {
ic <- ic + 1
x[[ic]] <- temp
if (ic == 1)
grpn <- matrix(c(cat1[i1], cat2[i2], cat3[i3]),
1, 3)
if (ic > 1)
grpn <- rbind(grpn, c(cat1[i1], cat2[i2],
cat3[i3]))
}
}
}
}
}
if (length(grpc) == 4) {
cat1 <- selby(m, grpc[1], coln)$grpn
cat2 <- selby(m, grpc[2], coln)$grpn
cat3 <- selby(m, grpc[3], coln)$grpn
cat4 <- selby(m, grpc[4], coln)$grpn
x <- vector("list")
ic <- 0
for (i1 in 1:length(cat1)) {
for (i2 in 1:length(cat2)) {
for (i3 in 1:length(cat3)) {
for (i4 in 1:length(cat4)) {
temp <- NA
it <- 0
for (i in 1:nrow(m)) {
if (sum(m[i, c(grpc[1], grpc[2], grpc[3],
grpc[4])] == c(cat1[i1], cat2[i2], cat3[i3],
cat4[i4])) == 4) {
it <- it + 1
temp[it] <- m[i, coln]
}
}
if (!is.na(temp[1])) {
ic <- ic + 1
x[[ic]] <- temp
if (ic == 1)
grpn <- matrix(c(cat1[i1], cat2[i2],
cat3[i3], cat4[i4]), 1, 4)
if (ic > 1)
grpn <- rbind(grpn, c(cat1[i1], cat2[i2],
cat3[i3], cat4[i4]))
}
}
}
}
}
}
list(x = x, grpn = grpn)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.