Adding custom row(s) to an LaTeX-outputted R table of regression results using memisc, xtable etc.
Date : March 29 2020, 07:55 AM
it fixes the issue You might try to add that new line(s) directly to the table you want to pass to e.g. xtable. Really lame example: m <- lm(mtcars$hp ~ mtcars$wt)
df <- as.data.frame(summary(m)$coefficient)
df[3, ] <- c(sample(c('foo', 'bar'), 4, replace = TRUE))
rownames(df)[3] <- 'FOOBAR'
> df
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.82092177119464 32.3246158121787 -0.0563323561763288 0.95545056134944
mtcars$wt 46.1600502824445 9.62530003926982 4.79569988406785 4.14582744107531e-05
FOOBAR bar foo bar bar
> xtable(df)
% latex table generated in R 2.15.0 by xtable 1.7-0 package
% Tue Jun 12 01:39:46 2012
\begin{table}[ht]
\begin{center}
\begin{tabular}{rllll}
\hline
& Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\
\hline
(Intercept) & -1.82092177119464 & 32.3246158121787 & -0.0563323561763288 & 0.95545056134944 \\
mtcars\$wt & 46.1600502824445 & 9.62530003926982 & 4.79569988406785 & 4.14582744107531e-05 \\
FOOBAR & bar & foo & bar & bar \\
\hline
\end{tabular}
\end{center}
\end{table}
|
sql, matching row values obtained from first table to the column names of second table without loop
Tag : python , By : user187301
Date : March 29 2020, 07:55 AM
this will help You don't need to re-query the second table over and over again, you could just retrieve the one row once and use that as a lookup-table. If you use the sqlite3.Row row factory that is as easy as retrieving one row: memcon.row_factory = sqlite3.Row
memdata.execute("select * from tabletwo where tabletwo.Gene_ID == 'NFYA'")
nfya_row = memdata.fetchone()
memdata.execute("SELECT tableone.SampleID from tableone WHERE tableone.Diagnos=='RH'")
for row in memdata:
sampleID = row['SampleID']
print sampleID, nfya_row[sampleID]
memdata.execute("select * from tabletwo where tabletwo.Gene_ID == 'NFYA'")
nfya_row = {desc[0]: column for desc, column in zip(memdata.getdescription(), memdata.next())}
memdata.execute("SELECT tableone.SampleID from tableone WHERE tableone.Diagnos=='RH'")
for row in memdata:
sampleID = row[0]
print sampleID, nfya_row[sampleID]
|
xtable for MANOVA object obtained with car package
Tag : r , By : Thomas Plunkett
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The problem is that xtable has a method for objects of class anova, but the car package's Anova function returns an object of class anova.mlm. I found a fix at https://stat.ethz.ch/pipermail/r-help/2009-June/201478.html: library(xtable)
library(car)
# Create some example data
Pottery <- data.frame(
"Al" = rnorm(10),
"Fe" = rnorm(10),
"Mg" = rnorm(10),
"Ca" = rnorm(10),
"Na" = rnorm(10),
"Site" = sample(LETTERS[1:2], 10, replace = TRUE))
# Create a custom function handling `anova.mlm` objects
xtable.Anova.mlm <- function (x, ...) {
test <- x$test
repeated <- x$repeated
ntests <- length(x$terms)
tests <- matrix(NA, ntests, 4)
if (!repeated)
SSPE.qr <- qr(x$SSPE)
for (term in 1:ntests) {
eigs <- Re(eigen(qr.coef(if (repeated) qr(x$SSPE[[term]]) else
SSPE.qr,
x$SSP[[term]]), symmetric = FALSE)$values)
tests[term, 1:4] <- switch(test, Pillai = stats:::Pillai(eigs,
x$df[term], x$error.df), Wilks = stats:::Wilks(eigs,
x$df[term], x$error.df), `Hotelling-Lawley` = stats:::HL(eigs,
x$df[term], x$error.df), Roy = stats:::Roy(eigs,
x$df[term], x$error.df))
}
ok <- tests[, 2] >= 0 & tests[, 3] > 0 & tests[, 4] > 0
ok <- !is.na(ok) & ok
tests <- cbind(x$df, tests, pf(tests[ok, 2], tests[ok, 3],
tests[ok, 4], lower.tail = FALSE))
rownames(tests) <- x$terms
colnames(tests) <- c("Df", "test stat", "approx F", "num Df",
"den Df", "Pr(>F)")
tests <- structure(as.data.frame(tests), heading = paste("\nType ",
x$type, if (repeated)
" Repeated Measures", " MANOVA Tests: ", test, " test
statistic",
sep = ""), class = c("anova", "data.frame"))
# print(tests)
# invisible(x)
xtable(tests)
}
MANOVA <- Anova(lm(cbind(Al, Fe, Mg, Ca, Na) ~ Site, data=Pottery))
xtable(MANOVA)
% latex table generated in R 2.15.2 by xtable 1.7-1 package
% Tue Jun 11 20:49:51 2013
\begin{table}[ht]
\centering
\begin{tabular}{lrrrrrr}
\hline
& Df & test stat & approx F & num Df & den Df & Pr($>$F) \\
\hline
Site & 1 & 0.61 & 1.24 & 5 & 4 & 0.4288 \\
\hline
\end{tabular}
\end{table}
|
knitr, R Markdown, and xtable: xtable tables within HTML table
Tag : html , By : Jason Vance
Date : March 29 2020, 07:55 AM
this will help I think your code will work if you put results=asis in the chunk options. <table border = 1>
<tr>
<td>
```{r results='asis', echo=FALSE}
library(xtable)
data(tli)
print(xtable(tli[1:20, ]),type='html')
```
</td>
<td>
```{r results='asis', echo=FALSE}
library(xtable)
data(tli)
print(xtable(tli[1:20, ]),type='html',comment=FALSE)
```
</td>
</tr>
</table>
|
How to set spaces in the column names of a table or data frame using xtable
Date : March 29 2020, 07:55 AM
To fix this issue So I want to use spaces among words in the names of the columns of a data frame and print the data frame to a pdf in latex format. However, when I use xtable() to do this, the names of the columns get joined. , Your best bet is probably to use the sanitize.* options, e.g.: > print.xtable(xtable(dat),include.rownames=F,
sanitize.colnames.function=function(x)gsub("\\."," ",x))
% latex table generated in R 3.2.1 by xtable 1.7-4 package
% Thu Aug 20 10:47:54 2015
\begin{table}[ht]
\centering
\begin{tabular}{llll}
\hline
Variable & Categoría de Referencia & Categoría Considerada & Variación \\
\hline
Uso & No Acaba Unidad & Acaba la Unidad & 2.08\% \\
País & Brasil & España & 0.31\% \\
País & Brasil & Francia & 0.46\% \\
País & Brasil & ITalia & 0.7\% \\
País & Brasil & Méjico & -0.19\% \\
País & Brasil & Otros Países & -0.46\% \\
Clicker & Clicker & No Cliker & -2.32\% \\
App & No Usa App & Usa App & 1.15\% \\
\hline
\end{tabular}
\end{table}
datmat<-as.matrix(dat)
colnames(datmat)<-c("Variable","Categoría de Referencia",
"Categoría Considerada", "Variación")
print.xtable(xtable(datmat),include.rownames=F)
|