Skip to content
Prev 263293 / 398502 Next

WG: R-Problem

cut() and table() will do it. Here's one less-than-elegant way to put
them together:

test <- structure(list(X1 = c(0, 1.3, 1.6, 2.1), X2 = c(1.3, 0, 1.9,
1.7), X3 = c(1.6, 1.9, 0, 2.2), X4 = c(2.1, 1.7, 2.2, 0)), .Names = c("X1",
"X2", "X3", "X4"), class = "data.frame", row.names = c("1", "2",
"3", "4"))

test1 <- apply(test, 2, cut, breaks=seq(0, 2.5, by=.5),
labels=c("0.5", "1", "1.5", "2", "2.5"))

apply(test1, 2, function(x)table(factor(x, levels=c("0.5", "1", "1.5",
"2", "2.5"))))

Sarah


On Tue, Jun 21, 2011 at 10:43 AM, Bleicher Niels (AFS)
<niels.bleicher at zuerich.ch> wrote: