English 中文(简体)
R[闭门]制作晚间表格的工具
原标题:Tools for making latex tables in R [closed]
  • 时间:2011-03-28 21:31:11
  •  标签:
  • r
  • latex
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.

根据一般要求,一个社区维基将在R生产晚餐桌。 在这一员额中,Ill概括介绍了最常用的包裹和博客,其中含有从不太直截面的物体制作晚餐表的编码。 请自由补充我所忽略的任何情况,并(或)就如何与R一道制作冰化格式的晚餐桌,提供简便、背后和小滴。

Packages :

  • xtable : for standard tables of most simple objects. A nice gallery with examples can be found here.
  • memisc : tool for management of survey data, contains some tools for latex tables of (basic) regression model estimates.
  • Hmisc contains a function latex() that creates a tex file containing the object of choice. It is pretty flexible, and can also output longtable latex tables. There s a lot of info in the help file ?latex
  • miscFuncs has a neat function latextable that converts matrix data with mixed alphabetic and numeric entries into a LaTeX table and prints them to the console, so they can be copied and pasted into a LaTeX document.
  • texreg package (JSS paper) converts statistical model output into LaTeX tables. Merges multiple models. Can cope with about 50 different model types, including network models and multilevel models (lme and lme4).
  • reporttools package (JSS paper) is another option for descriptive statistics on continuous, categorical and date variables.
  • tables package is perhaps the most general LaTeX table making package in R for descriptive statistics
  • stargazer package makes nice comparative statistical model summary tables

Blogs and code snippets

Related questions :

问题回答

我要补充一提“变”一揽子计划。 您可以撰写一份模版文件,即LTeX与地主的版面,然后“浏览”,以建立一个顶端文件,列入或输入你的LaTeX。 类似:

egin{tabular}{l l}
A & <%= fit$A %> \
B & <%= fit$B %> \
end{tabular}

浏览器也可处理假肢,这样,你就可以为每个数据机的浏览建立一个桌子。

感谢Joris先生提出这一问题。 希望能够进入社区。

晚期的书表编制冰冰表。 http://cameron.bracken.bz/sweave-xtable-booktabs”

I would also add the apsrtable package to the mix as it produces nice looking regression tables.

另一种想法: 其中一些一揽子计划(表格和缩略语)允许方便地推广该守则,为不同的回归物体编制表格。 这方面的一个例子是问题中显示的四流式代码。 启动一个储存库以收集此类编码信标可能是有益的,而且随着时间的推移,可能甚至会增加这一材料。 任何接收者?

我有几条trick子,并围绕我在这里分享的食肉和快乐的有趣特征开展工作。

www.un.org/Depts/DGACM/index_spanish.htm Trick #1: 在Columns和Trick #: 采用书目

第一,装载包和界定我的清洁功能

<<label=first, include=FALSE, echo=FALSE>>= 
    library(xtable)
    library(plyr)

    cleanf <- function(x){     
        oldx <- c(FALSE, x[-1]==x[-length(x)])  
        # is the value equal to the previous?    
        res <- x
        res[oldx] <- NA
        return(res)} 

现在产生一些假数据

data<-data.frame(animal=sample(c("elephant", "dog", "cat", "fish", "snake"), 100,replace=TRUE),
            colour=sample(c("red", "blue", "green", "yellow"), 100,replace=TRUE),
            size=rnorm(100,mean=500, sd=150),
            age=rlnorm(100, meanlog=3, sdlog=0.5))

    #generate a table
    datatable<-ddply(data, .(animal, colour), function(df) {
                return(data.frame(size=mean(df$size), age=mean(df$age)))
            })

现在我们可以编制一个表格,并利用清洁功能消除标签栏中的重复条目。

cleandata<-datatable
cleandata$animal<-cleanf(cleandata$animal)
cleandata$colour<-cleanf(cleandata$colour)
@ 

这是正常的。

<<label=normal, results=tex, echo=FALSE>>=
print(
    xtable(
        datatable
        ),
        tabular.environment= longtable ,
        latex.environments=c("center"), 
        floating=FALSE, 
        include.rownames=FALSE
    )
@ 

这是正常的。 where a custom function has turned duplicates to NA

<<label=cleandata, results=tex, echo=FALSE>>=
print(
    xtable(
        cleandata
        ),
        tabular.environment= longtable ,
        latex.environments=c("center"), 
        floating=FALSE, 
        include.rownames=FALSE
    )
@ 

This table uses the booktab package (and needs a usepackage{booktabs} in the headers)

egin{table}[!h] 
        centering
        caption{table using booktabs.}
        label{tab:mytable}
<<label=booktabs, echo=F,results=tex>>= 
            mat <- xtable(cleandata,digits=rep(2,ncol(cleandata)+1))
            foo<-0:(length(mat$animal))
            bar<-foo[!is.na(mat$animal)]
            print(mat, 
                  sanitize.text.function = function(x){x},
                  floating=FALSE,
                  include.rownames=FALSE,
                  hline.after=NULL, 
                  add.to.row=list(pos=list(-1,bar,nrow(mat)), 
                  command=c("\toprule ", "\midrule ", "\bottomrule ")))
  #could extend this with cmidrule to have a partial line over
  #a sub category column and addlinespace to add space before a total row
@ 

一揽子食堂中的两家公用事业可以协同使用,以制作多功能的nes子。

library(datasets)
library(taRifx)
library(xtable)

test.by <- bytable(ChickWeight$weight, list( ChickWeight$Chick, ChickWeight$Diet) )
colnames(test.by) <- c( Diet , Chick , Mean Weight )
print(latex.table.by(test.by), include.rownames = FALSE, include.colnames = TRUE, sanitize.text.function = force)
#   then add usepackage{multirow} to the preamble of your LaTeX document
#   for longtable support, add ,tabular.environment= longtable  to the print command (plus add in ,floating=FALSE), then usepackage{longtable} to the LaTeX preamble

sample table output

...和Trick #3 缩略语

Generate some more data

moredata<-data.frame(Nominal=c(1:5), n=rep(5,5), 
        MeanLinBias=signif(rnorm(5, mean=0, sd=10), digits=4), 
        LinCI=paste("(",signif(rnorm(5,mean=-2, sd=5), digits=4),
                ", ", signif(rnorm(5, mean=2, sd=5), digits=4),")",sep=""),
        MeanQuadBias=signif(rnorm(5, mean=0, sd=10), digits=4), 
        QuadCI=paste("(",signif(rnorm(5,mean=-2, sd=5), digits=4),
                ", ", signif(rnorm(5, mean=2, sd=5), digits=4),")",sep=""))

names(moredata)<-c("Nominal", "n","Linear Model 
Bias","Linear 
CI", "Quadratic Model 
Bias", "Quadratic 
CI")

如今,利用沉积功能,用正确的晚期新线指挥取代栏目(包括两点击,使R高兴)

<<label=multilinetable, results=tex, echo=FALSE>>=
foo<-xtable(moredata)
align(foo) <- c( rep( c ,3), p{1.8in} , p{2in} , p{1.8in} , p{2in}  )
print(foo, 
            floating=FALSE, 
            include.rownames=FALSE,
            sanitize.text.function = function(str) {
                str<-gsub("
","\\", str, fixed=TRUE)

                return(str)
            }, 
            sanitize.colnames.function = function(str) {
                str<-c("Nominal", "n","\centering Linear Model\\ \% Bias","\centering Linear \\ 95\%CI", "\centering Quadratic Model\\ \%Bias", "\centering Quadratic \\ 95\%CI \tabularnewline")
                return(str)
            })
@  

(尽管这是一帆风顺的,因为我们需要一条新路线,以便表格格式正确,而Xtable仍然处于最后的状态,因此,我们最后在表头下面有一个空白线。)

您也可以利用从区域一揽子计划中产生的可读功能:

rel=“noreferer”>http://cran.r-project.org/web/ Packages/miscFuncs/index.html

可读性(M)中,M是一种混合体的甲型和识数条目矩阵,在屏幕上制作了一个基本的LTeX表,可以复制并贴在LTeX文件中。 如果有小数,也用指数表示取而代之(如1.2x10 ±-3})。

另一项将多个回归模型合并到LaTeX表格的R套件是texreg





相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...