Dear Rxperts!
Thanks for the suggestions...(esp. Dr. Mathemedician)! :)

I add one more factor level (a level higher to "a") in the example..
a <- data.frame(p=rep(c("A","B"),each=10,len=30),
a=rep(c(1,2,3),each=10),id=seq(30),
b=round(runif(30,10,20)),
c=round(runif(30,40,70)))

tabular(((p=factor(p))*(a=factor(a))+1) ~ (N = 1) + (b + c)*
(mean+sd),data=a)

             b               c
 p a   N  mean  sd    mean  sd
 A 1   10 16.30 2.497 52.30  9.358
   2    0   NaN    NA   NaN     NA
   3   10 15.60 2.716 60.30  8.001
 B 1    0   NaN    NA   NaN     NA
   2   10 15.40 2.366 57.70 10.414
   3    0   NaN    NA   NaN     NA
   All 30 15.77 2.473 56.77  9.601

How do I remove the lines which N=0 or the columns with NaN or NA? I could
not make the subsetting....
I can't generate the above resulting table look like..

             b               c
 p a   N  mean  sd    mean  sd
 A 1   10 16.30 2.497 52.30  9.358
     3   10 15.60 2.716 60.30  8.001
 B  2   10 15.40 2.366 57.70 10.414
   All 30 15.77 2.473 56.77  9.601


Thanks so much,
Santosh


On Fri, Apr 19, 2013 at 3:15 PM, David Winsemius <dwinsem...@comcast.net>wrote:

>
> 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 <dwinsem...@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
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to