[R] Obtaining summary of frequencies of value occurrences for a variable in a multivariate dataset.
ggrothendieck at gmail.com
Wed Jul 25 13:54:05 CEST 2007
PR10 PR11 PR12 PR13 PR14 PR15 PR16
V:10 S:7 I:10 K:8 I:2 E:1 D:1
T:3 R:2 V:8 G:9 G:9
On 7/25/07, Allan Kamau <kamauallan at yahoo.com> wrote:
> A subset of the data looks as follows
> > df[1:10,14:20]
> PR10 PR11 PR12 PR13 PR14 PR15 PR16
> 1 V T I K V G D
> 2 V S I K V G G
> 3 V T I R V G G
> 4 V S I K I G G
> 5 V S I K V G G
> 6 V S I R V G G
> 7 V T I K I G G
> 8 V S I K V E G
> 9 V S I K V G G
> 10 V S I K V G G
> The result I would like is as follows
> PR10 PR11 PR12 ...
> [V:10] [S:7,T:3] [I:10]
> The result can be in a matrix or a vector and each variablename, value and frequency should be accessible so as to be used for comparisons with another dataset later.
> The frequency can be a count or a percentage.
> ----- Original Message ----
> From: Adaikalavan Ramasamy <ramasamy at cancer.org.uk>
> To: Allan Kamau <kamauallan at yahoo.com>
> Cc: r-help at stat.math.ethz.ch
> Sent: Tuesday, July 24, 2007 10:21:51 PM
> Subject: Re: [R] Obtaining summary of frequencies of value occurrences for a variable in a multivariate dataset.
> The name of the table should give you the "value". And if you have a
> matrix, you just need to convert it into a vector first.
> > m <- matrix( LETTERS[ c(1:3, 3:5, 2:4) ], nc=3 )
> > m
> [,1] [,2] [,3]
> [1,] "A" "C" "B"
> [2,] "B" "D" "C"
> [3,] "C" "E" "D"
> > tb <- table( as.vector(m) )
> > tb
> A B C D E
> 1 2 3 2 1
> > paste( names(tb), ":", tb, sep="" )
>  "A:1" "B:2" "C:3" "D:2" "E:1"
> If this is not what you want, then please give a simple example.
> Regards, Adai
> Allan Kamau wrote:
> > Hi all,
> > If the question below as been answered before I
> > apologize for the posting.
> > I would like to get the frequencies of occurrence of
> > all values in a given variable in a multivariate
> > dataset. In short for each variable (or field) a
> > summary of values contained with in a value:frequency
> > pair, there can be many such pairs for a given
> > variable. I would like to do the same for several such
> > variables.
> > I have used table() but am unable to extract the
> > individual value and frequency values.
> > Please advise.
> > Allan.
> > ______________________________________________
> > 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.
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help