[R] [Newbie] Is there any support for work with grouped frequencies?

Matej Cepl matej at ceplovi.cz
Wed Nov 13 21:13:10 CET 2002


On Wed, Nov 13, 2002 at 07:16:32PM +0100, Christian Schulz wrote:
> try this
> 
> tapply(variable,group,summary)
> 
> ...instead of "summary" you can use other functions like mean.

I do not think, that it makes any sense to take mean from one
value of every valuable (which is what I do with tapply here,
don't I?).

	Matej

	> tab
					  LABEL FREQ MIDPOINT
	1  Infant (under 1)    0      1.0
	2            1 to 4    5      2.5
	3            5 to 8    1      6.5
	4           9 to 12    3     10.5
	5          13 to 16    0     14.5
	6          17 to 19    3     18.0
	7          20 to 24  117     22.0
	8          25 to 29  341     27.0
	9          30 to 34  503     32.0
	10         35 to 39  578     37.0
	11         40 to 44  510     42.0
	12         45 to 49  369     47.0
	13         50 to 54  272     52.0
	14         55 to 59  177     57.0
	15         60 to 64   79     62.0
	16         65 to 69   29     67.0
	17         70 to 74   15     72.0
	18      75 and over   11     75.0
	19          Unknown   NA       NA
	>
	> tapply(tab$FREQ,tab$LABEL,mean)
	Infant (under 1)          Unknown           1 to 4         13 to
	16
						0               NA
	5                0
			  17 to 19         20 to 24         25 to 29         30 to
	34
						3              117              341
	503
			  35 to 39         40 to 44         45 to 49           5 to
	8
					 578              510              369
	1
			  50 to 54         55 to 59         60 to 64         65 to
	69
					 272              177               79
	29
			  70 to 74      75 and over          9 to 12
					  15               11                3

-- 
Matej Cepl, matej at ceplovi.cz,
Finger: 89EF 4BC6 288A BF43 1BAB  25C3 E09F EF25 D964 84AC
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488
 
All parts should go together without forcing. You must remember
that the parts you are reassembling were disassembled by you.
Therefore, if you can't get them together again, there must be a
reason. By all means, do not use a hammer.
    -- IBM maintenance manual, 1925

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list