Hi
r-help-boun...@r-project.org napsal dne 13.01.2010 01:36:31:
tmp - scan()
0 2 1 0 1 0 2 1 2 3 0 0 0 0 1 0 0 2 3 1
dat - matrix(tmp, byrow=T, ncol=4)
apply(dat, 2, function(x, min.val, max.val) {
tmp - table(x)/length(x)
res - rep(0, max.val - min.val + 1)
Dear friends,
I have a table like this, I have A B C D ... levels, the first column
you see is just the index, and there are different numbers in the
table.
A B C D ...
10 2 1 0
21 0 2 1
32 3 0 0
40 0 1 0
50 2 3 1
...
I want to
tmp - scan()
0 2 1 0 1 0 2 1 2 3 0 0 0 0 1 0 0 2 3 1
dat - matrix(tmp, byrow=T, ncol=4)
apply(dat, 2, function(x, min.val, max.val) {
tmp - table(x)/length(x)
res - rep(0, max.val - min.val + 1)
res[as.numeric(names(tmp)) - min.val + 1] - tmp
res
}, 0, 3)
Should do it (but I bet
3 matches
Mail list logo