[R] simple question with table()
Chuck Cleland
ccleland at optonline.net
Sun Nov 30 11:18:18 CET 2008
On 11/30/2008 5:05 AM, 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
Make the responses to the question a factor and set the levels of the
factor to include all 14 possible answers. For example:
> table(factor(rep(c('1','2'), each=7), levels=c('1','2','3')))
1 2 3
7 7 0
?factor
> 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.
--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894
More information about the R-help
mailing list