Hi R-gurus,
I have a matrix which looks like
00000000000
01110000220
01110000220
01110000000
00000000000
As you can see we have non-zero levels 1 and 2. I would like to fill an other
matrix with the frequency of non-zero levels in each cell. The results that I
need is
00000000000
09990000440
09990000440
09990000000
00000000000
If I run the script below I can simulate the first matrix and count the cells
for each non-zero levels. My question is how can I fill the second matrix in a
easy way.
my.mat<-matrix(
c(0,0,0,0,0,0,0,0,0,0,0,
0,1,1,1,0,0,0,0,2,2,0,
0,1,1,1,0,0,0,0,2,2,0,
0,1,1,1,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0),nrow=5,byrow=T)
my.mat.freq<-data.frame(table(my.mat))
my.mat.freq<-subset(my.mat.freq,my.mat.freq$my.mat!=0)
my.mat.freq
Any idea?
Kind regards
Miltinho
para armazenamento!
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.