# [R] tables package - error message of "duplicate values"

David Winsemius dwinsemius at comcast.net
Fri Apr 19 22:53:07 CEST 2013

```On Apr 19, 2013, at 1:29 PM, Santosh wrote:

> Dear expeRts!
> when I try summarize data using "tabular" of tables package..
>
> here is an example..
>> a <-
> data.frame(a=rep(10,10),b=round(runif(10,10,20)),c=round(runif(10,40,50)))
>> a
>    a  b  c
> 1  10 14 44
> 2  10 17 40
> 3  10 13 40
> 4  10 18 40
> 5  10 11 49
> 6  10 16 46
> 7  10 15 43
> 8  10 19 49
> 9  10 19 49
> 10 10 13 45
>> tabular((a+1)~(n=1)+Format(dig=0)*(b + c) * (mean + sd),data=a)
> Error in term2table(rows[[i]], cols[[j]], data, n) :
>  Duplicate values: a and b
>
> Is there a way to let the function  accept the "apparently" duplicate
> values?

I don't consider myself an expert, just one who reads the manuals and makes modest adjustments to the help-page examples.  Perhaps if you explained what you thought the correct answer would be ( and can you please explain why you are setting digits=0?

tabular( 1~Format(digits=2) *(b+c)* (mean + sd),data=a)
#-------------------------
b         c
mean sd   mean sd
All 14.9  3.0 44.3  2.9
#-----------------
# Putting a numeric variable on the LHS appears to fail but wrapping it in factor() allows success:

> a<-data.frame(a=rep(c(1,2),10),b=round(runif(10,10,20)),c=round(runif(10,40,50)))
>
> tabular( (factor(a) +1)~Format(digits=2) *(b+c)* (mean + sd),data=a)
#----------
b         c
factor(a) mean sd   mean sd
1         15.2  3.7 45.0  2.6
2         13.0  3.5 48.2  1.2
All       14.1  3.7 46.6  2.6

--

David Winsemius
Alameda, CA, USA

```