An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20040229/c877fa38/attachment.pl
Proportions again
5 messages · Carlos Mauricio Cardeal Mendes, Andrew Robinson, Chuck Cleland +2 more
table(sex)/length(sex) Andrew
On Sunday 29 February 2004 06:35, Carlos Mauricio Cardeal Mendes wrote:
Hello. I asked before and it was great, cause as a beginner I learned a lot. But,
if I have this in R (1 and 2 are codes for sex):
sex<-c(1,2,2,1,1,2,2,2) sex
[1] 1 2 2 1 1 2 2 2 I?d like to obtain the proportion according to sex.So I type:
prop.table(sex)
[1] 0.07692308 0.15384615 0.15384615 0.07692308 0.07692308 0.15384615
0.15384615 [8] 0.15384615
The result is OK, but I expected to see a simple frequency table or
something like that:
1 0.375
2 0.625
1.0
How can I get this ?
Thank you very much
[[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : andrewr at uidaho.edu PO Box 441133 W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion.
Carlos Mauricio Cardeal Mendes wrote: I asked before and it was great, cause as a beginner I learned a lot. But, if I have this in R (1 and 2 are codes for sex):
sex<-c(1,2,2,1,1,2,2,2) sex
[1] 1 2 2 1 1 2 2 2 I?d like to obtain the proportion according to sex.So I type:
prop.table(sex)
[1] 0.07692308 0.15384615 0.15384615 0.07692308 0.07692308 0.15384615
0.15384615 [8] 0.15384615
The result is OK, but I expected to see a simple frequency table or
something like that:
1 0.375
2 0.625
1.0
How can I get this ?
prop.table(table(sex))
Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894
Dear Carlos, prop.table() takes a table as its argument, so you could specify prop.table(table(sex)). See ?prop.table for more details. John
-----Original Message----- From: r-help-bounces+jfox=mcmaster.ca at stat.math.ethz.ch [mailto:r-help-bounces+jfox=mcmaster.ca at stat.math.ethz.ch] On Behalf Of Carlos Mauricio Cardeal Mendes Sent: Sunday, February 29, 2004 9:35 AM To: r-help at stat.math.ethz.ch Subject: [R] Proportions again Hello. I asked before and it was great, cause as a beginner I learned a lot. But, if I have this in R (1 and 2 are codes for sex):
sex<-c(1,2,2,1,1,2,2,2) sex
[1] 1 2 2 1 1 2 2 2 I?d like to obtain the proportion according to sex.So I type:
prop.table(sex)
[1] 0.07692308 0.15384615 0.15384615 0.07692308 0.07692308
0.15384615 0.15384615 [8] 0.15384615
The result is OK, but I expected to see a simple frequency
table or something like that:
1 0.375
2 0.625
1.0
How can I get this ?
Andrew Robinson <andrewr at uidaho.edu> writes:
table(sex)/length(sex)
or, as is the intended usage:
prop.table(table(sex))
sex
1 2
0.375 0.625
I asked before and it was great, cause as a beginner I learned a lot. But,
if I have this in R (1 and 2 are codes for sex):
sex<-c(1,2,2,1,1,2,2,2) sex
[1] 1 2 2 1 1 2 2 2 I?d like to obtain the proportion according to sex.So I type:
prop.table(sex)
[1] 0.07692308 0.15384615 0.15384615 0.07692308 0.07692308 0.15384615
0.15384615 [8] 0.15384615
The result is OK, but I expected to see a simple frequency table or
something like that:
1 0.375
2 0.625
1.0
How can I get this ?
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907