[R] simple question with table()

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Sun Nov 30 11:19:04 CET 2008


you have to use a factor, e.g.,

x <- sample((1:14)[-13], 100, TRUE)
f <- factor(x, levels = 1:14)
table(f)


I hope it helps.

Best,
Dimitris


Simone Gabbriellini wrote:
> Dear List,
> 
> my problem should be easy to fix, but I couldn't find a solution by 
> myself...
> 
> In my survey, there is a question with 14 possible answers. None of the 
> respondents choose the 13th answer, so when I table() the results, R says:
> 
> 1    2    3    4    5    6    7    8    9    10    11    12    14
> 31    52    7    21    40    7    8    2    28    2    2    1    17
> 
> 13 is missing... anyone knows how to tell table() that there are 14 
> modalities in the answers? I tried with
> 
> responseName=c("1","2","3","4","5","6","7","8","9","10","11","12","13","14") 
> 
> 
> but all I have is:
> 
> error in table....
> all the arguments must have the same length
> 
> thank you,
> Simone
> 
> ______________________________________________
> R-help at r-project.org 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.
> 

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014



More information about the R-help mailing list