[R] Tables extraction in R ?

David L Carlson dcarlson at tamu.edu
Sun Jul 8 01:03:39 CEST 2012


You could use xtable (no "s"). It produces latex and html formats, but for
Excel you want to use html format. 

> library(xtable)
> agec <- sample(c(rep(1, 15), rep(2, 4), 3), 1000, replace=TRUE)
> table(agec)
> agec
  1   2   3 
759 202  39 
> print(xtable(table(agec)), type="html", file="clipboard-128")

The print command copies the html formatted table into the Windows
Clipboard. Now just open an Excel spreadsheet and paste the table into it.

Or change "clipboard-128" to "mytable.html" and import the table. 

But you also asked about making a graphics version. For that you probably
want addtable2plot() in the plotrix package. For example:

> library(plotrix)
> tbl <- table(agec)
> tbldf <- as.data.frame.table(tbl)
> barplot(tbl)
> addtable2plot(2, 500, tbldf)

Or if you just want the table:

> plot(0:3, 0:3, xlab="", ylab="", type="n", axes=FALSE)
> addtable2plot(1, 1, tbldf, cex=2)

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352




> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of John Kane
> Sent: Friday, July 06, 2012 12:55 PM
> To: Greeknovice; r-help at r-project.org
> Subject: Re: [R] Tables extraction in R ?
> 
> Have a look at the xtables package.  I have not used it in some time
> but I think it may do what you want.  A google search "R statistics
> xtables" should bring up some useful information on this.
> 
> John Kane
> Kingston ON Canada
> 
> 
> > -----Original Message-----
> > From: sggko87 at gmail.com
> > Sent: Fri, 6 Jul 2012 10:23:13 -0700 (PDT)
> > To: r-help at r-project.org
> > Subject: [R] Tables extraction in R ?
> >
> > Hi,
> > I 'm a novice user of R statistics and my hands-on experience with it
> is
> > minimal.
> > I want to create a table for my MBA course assignment that looks like
> the
> > ones that SPSS and MS Excel produces ,the data that the table has to
> > include
> > are the following :
> >
> >> table(agec)
> > agec
> >   1   2   3
> > 749 160  32
> >> x=table(agec)
> >> x
> > agec
> >   1   2   3
> > 749 160  32
> >>
> >> prop.table(x)
> > agec
> >          1          2          3
> > 0.79596174 0.17003188 0.03400638
> >> prop.test(749,941)
> >
> >         1-sample proportions test with continuity correction
> >
> > data:  749 out of 941, null probability 0.5
> > X-squared = 328.5186, df = 1, p-value < 2.2e-16
> > alternative hypothesis: true p is not equal to 0.5
> > 95 percent confidence interval:
> >  0.7684801 0.8209873
> > sample estimates:
> >         p
> > 0.7959617
> >
> >> prop.test(160,941)
> >
> >         1-sample proportions test with continuity correction
> >
> > data:  160 out of 941, null probability 0.5
> > X-squared = 408.5016, df = 1, p-value < 2.2e-16
> > alternative hypothesis: true p is not equal to 0.5
> > 95 percent confidence interval:
> >  0.1468831 0.1959230
> > sample estimates:
> >         p
> > 0.1700319
> >
> >> prop.test(32,941)
> >
> >         1-sample proportions test with continuity correction
> >
> > data:  32 out of 941, null probability 0.5
> > X-squared = 815.4899, df = 1, p-value < 2.2e-16
> > alternative hypothesis: true p is not equal to 0.5
> > 95 percent confidence interval:
> >  0.02374674 0.04822644
> > sample estimates:
> >          p
> > 0.03400638
> > This "percentages and confidence intrevals"  table should be  in an
> image
> > file format since I have to upload it to a wiki page.
> > Is there a specific command or even a series of commands I can use in
> > order
> > to extract this "graphics" table automatically, or I have to create
> it
> > manually using Excel for example?
> > Thanks,
> > S.G.Golf.
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/Tables-extraction-in-R-tp4635638.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > 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.
> 
> ____________________________________________________________
> Receive Notifications of Incoming Messages
> Easily monitor multiple email accounts & access them with a click.
> Visit http://www.inbox.com/notifier and check it out!
> 
> ______________________________________________
> 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.



More information about the R-help mailing list