[R] Simple table with frequency variable
jim holtman
jholtman at gmail.com
Wed Aug 1 22:38:43 CEST 2007
I am not exactly sure what you are asking for. I am assuming that you
want a vector that represent the combinations that are given
combinations that are present:
> N
[1] 11 22 31 42 51 12 21 32 41 52
> table(i,j)
j
i 1 2
1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
> z <- table(i,j)
> which(z==1)
[1] 1 2 3 4 5 6 7 8 9 10
> which(z==1,arr.ind=T)
row col
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
1 1 2
2 2 2
3 3 2
4 4 2
5 5 2
> x <- which(z==1,arr.ind=T)
> paste(rownames(z)[x[,'row']], colnames(z)[x[,'col']], sep='')
[1] "11" "21" "31" "41" "51" "12" "22" "32" "42" "52"
>
On 8/1/07, G. Draisma <g.draisma at erasmusmc.nl> wrote:
> Hallo,
>
> Im trying to find out how to tabulate frequencies
> of factors when the data have a frequency variable.
>
> e,g:
> i<-rep(1:5,2)
> j<-rep(1:2,5)
> N<-10*i+j
>
> table(i,j) gives a table of ones
> as each combination occurs only once.
> How does one get a table with the corresponding N's?
>
> Thanks!
> Gerrit.
>
>
> --
> Gerrit Draisma
> Department of Public Health
> Erasmus MC, University Medical Center Rotterdam
> Room AE-103
> P.O. Box 2040 3000 CA Rotterdam The Netherlands
> Phone: +31 10 4087124 Fax: +31 10 4638474
> http://mgzlx4.erasmusmc.nl/pwp/?gdraisma
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list