[R] tables package - error message of "duplicate values"
David Winsemius
dwinsemius at comcast.net
Sat Apr 20 00:15:00 CEST 2013
On Apr 19, 2013, at 2:03 PM, Santosh wrote:
> Rounding was done to replicate the problem I faced in the original data set...
I got an error every time I tried to use digits=0. My basic rule is that if a parameter choice consistently errors out ... stop using it. I'm fundamentally a pragmatist.
> 2 independent identifiers in a group (shown only for 1 of 7 groups) may have same value of b or c.
I don't understand what that means .... or why it should affect the ability of the program to deliver 'a'-level-specific estimates of the mean/sd values of 'b' & 'c' in the environment of data.frame-'a'. I showed that the problem was in not using factor() on the LHS of the formula when the grouping variable is numeric.
--
David.
>
>
> On Fri, Apr 19, 2013 at 1:53 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> 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
>
>
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list