[R] Rearranging long dataframe for printing in Sweave (andrecoding a factor)

Jean-Louis Abitbol abitbol at sent.com
Mon Jan 25 19:42:12 CET 2010


Ista,

Thanks, you got the question perfectly well.

And the proposed solution gets me on my way.

I just corrected the typo n.cbroup to n.cgroup.

Thanks again,

Best wishes, JL

On Mon, 25 Jan 2010 17:42 +0000, "Ista Zahn" <istazahn at gmail.com> wrote:
> If I understand the OP's issue correctly, this is how I would do it:
> 
> library(Hmisc)
> 
> test <- data.frame(conc=trunc(runif(1000,
> 1,1000)),nam=rep(c("A","B"),500))
> 
> final <- cbind(test[1:200,], test[201:400,], test[401:600,],
> test[601:800,], test[801:1000,])
> 
> latex(final, cgroup=c(paste("Obs. ",seq(1, 801, by=200), "-", seq(200,
> 1000, by=200), sep="")), n.cbroup=rep(2, 5), rowname=NULL)
> 
> Jean-Louis, is that what you were after, or did I misunderstand your
> question?
> 
> -Ista
> 
> On Mon, Jan 25, 2010 at 2:44 PM, Steve Sidney <sbsidney at mweb.co.za>
> wrote:
> > JL
> >
> > The solution which was proposed by Joseph Wright on the Latex Community
> > Forum was as follows
> >
> > 1) Use R to create the table and then save it in csv format
> >
> > 2) Use LaTex to print the table.
> >
> > 3) LaTex on it's own is not able to do this and you must install the
> > 'datatool' package.
> >
> > 4) What 'datatool' allows you to do is to read the csv into an internal
> > database and from that various very nice table printing styles can be
> > provided.
> >
> > 5) If you click on the link below provided by Liviu, you can follow the
> > postings between Joesph and myself and there are various code files as well
> > as pdf's which show how a single table with more rows than one page, can be
> > divided in two and placed one one page. If that's what you are looking for
> > then this might be a solution. The only problem is that if like me you don't
> > have strong LaTex skills, then you will have to do some experimenting and
> > learning, in order to achieve this result.
> >
> > HTH - Good luck
> > Steve
> >
> >
> > ----- Original Message ----- From: "Jean-Louis Abitbol" <abitbol at sent.com>
> > To: "Steve Sidney" <sbsidney at mweb.co.za>; "Liviu Andronic"
> > <landronimirc at gmail.com>
> > Cc: "R Help" <r-help at stat.math.ethz.ch>
> > Sent: Monday, January 25, 2010 9:18 AM
> > Subject: Re: [R] Rearranging long dataframe for printing in Sweave
> > (andrecoding a factor)
> >
> >
> > Hi Steve and Liviu,
> >
> > Thanks for the pointer to your posts.
> >
> > Steve can you share your elegant solution ?
> >
> > Up to now I have not had any answer from R-Help ...
> >
> > Best, JL
> >
> > On Sun, 24 Jan 2010 18:24 +0200, "Steve Sidney" <sbsidney at mweb.co.za>
> > wrote:
> >>
> >> Dear Liviu / Jean-Louis
> >>
> >> As the original poster I did find what I think is an elegant solution.
> >>
> >> The only remaining problem is that I have not been able to get it to work
> >> in
> >> Lyx, but it does work using a LaTeX editor (in this case WinEdt) and
> >> MikTex.
> >>
> >> I would still like to resolve why I can't read the csv table in Lyx.
> >>
> >> Regards
> >> Steve
> >>
> >> ----- Original Message ----- From: "Liviu Andronic"
> >> <landronimirc at gmail.com>
> >> To: "Jean-Louis Abitbol" <abitbol at sent.com>
> >> Cc: "R Help" <r-help at stat.math.ethz.ch>
> >> Sent: Sunday, January 24, 2010 5:56 PM
> >> Subject: Re: [R] Rearranging long dataframe for printing in Sweave
> >> (andrecoding a factor)
> >>
> >>
> >> > Hello
> >> >
> >> > On 1/24/10, Jean-Louis Abitbol <abitbol at sent.com> wrote:
> >> >>  I have to print a dataframe with >1000 rows and 2 columns for a report
> >> >>  done with Sweave.
> >> >>
> >> >>  I could use Hmisc latex function with longtable option.
> >> >>  However it is a waiste of space and paper given that I have only 2 (or
> >> >>  sometime 3) columns in the dataframe.
> >> >>
> >> >>  So it came to my mind that I could maybe  rearrange the dataframe and
> >> >>  create several new variables from the original 2 in a tabular way for
> >> >>  printing in less space.
> >> >>
> >> > There was a recent discussion on lyx-users [1] on a similar issue. I
> >> > am not sure whether the original poster found a solution, though.
> >> >
> >> > Liviu
> >> >
> >> > [1] http://www.mail-archive.com/lyx-users@lists.lyx.org/msg78933.html
> >> >
> >> > ______________________________________________
> >> > 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.
> >> >
> >>
> > --
> >  Jean-Louis Abitbol
> >  abitbol at sent.com
> >  Tel 33 (0)6 24 47 59 34
> >  1 ter Rue Céline, 92160
> >  Antony, France
> >
> > ______________________________________________
> > 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.
> >
> 
> 
> 
> -- 
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org
-- 
  Jean-Louis Abitbol
  abitbol at sent.com
  Tel 33 (0)6 24 47 59 34
  1 ter Rue Céline, 92160 
  Antony, France 



More information about the R-help mailing list