Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5849211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:58:05+00:00 2026-05-22T12:58:05+00:00

I wonder how to get LATEX table using xtable function from the following R

  • 0

I wonder how to get LATEX table using xtable function from the following R code.

Block <- gl(8, 4)
A <- factor(c(0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
          0,1,0,1,0,1,0,1,0,1,0,1))
B <- factor(c(0,0,1,1,0,0,1,1,0,1,0,1,1,0,1,0,0,0,1,1,
          0,0,1,1,0,0,1,1,0,0,1,1))
C <- factor(c(0,1,1,0,1,0,0,1,0,0,1,1,0,0,1,1,0,1,0,1,
          1,0,1,0,0,0,1,1,1,1,0,0))
Yield <- c(101, 373, 398, 291, 312, 106, 265, 450, 106, 306, 324, 449,
       272, 89, 407, 338, 87, 324, 279, 471, 323, 128, 423, 334,
       131, 103, 445, 437, 324, 361, 302, 272)
aovdat <- data.frame(Block, A, B, C, Yield)

summary(aov(Yield~Block+A*B+Error(A*Block), data=aovdat))


Error: A
  Df Sum Sq Mean Sq
A  1 3465.3  3465.3

Error: Block
      Df Sum Sq Mean Sq
Block  7   4499  642.71

Error: A:Block
          Df Sum Sq Mean Sq F value Pr(>F)
B          1  41616   41616  3.5354 0.1091
Residuals  6  70628   11771               

Error: Within
          Df Sum Sq Mean Sq F value  Pr(>F)  
B          1 119568  119568  7.3751 0.01673 *
A:B        1     28      28  0.0017 0.96734  
Residuals 14 226975   16213                  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Using the following code

xtable(summary(aov(Yield~Block+A*B+Error(A*Block), data=aovdat)))

producing the following error

Error in rbind(deparse.level, ...) : 
  numbers of columns of arguments do not match

Is it possible to get a LaTeX table like this?

SOV       Df Sum Sq Mean Sq F value  Pr(>F)  
A          1 3465.3  3465.3
Block      7   4499  642.71
B          1  41616   41616  3.5354 0.1091
Residuals  6  70628   11771               
B          1 119568  119568  7.3751 0.01673 *
A:B        1     28      28  0.0017 0.96734  
Residuals 14 226975   16213                  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:58:06+00:00Added an answer on May 22, 2026 at 12:58 pm

    summary is producing four tables in a list, so using lapply like so:

    mod <- aov(Yield ~ Block + A * B + Error(A * Block), data=aovdat)
    lapply(summary(mod), xtable)
    

    will produce a list of LaTeX tables.

    A for loop with print will produce the LaTeX code only, with the table names in the LaTeX caption.

    for (i in 1:4) print(xtable(summary(mod)[[i]], names(summary(mod)[i])))
    

    If you want all the tables as one, you need to do a bit of work because rbind doesn’t like tables with different numbers of columns. rbind.fill in the plyr package will do the job

    library(plyr)
    
    aovtab <- do.call(rbind.fill, lapply(1:length(summary(mod)), 
      function(x) unclass(summary(mod)[[x]])[[1]]))
    

    but we have to manually add the rownames back as data because a) rbind.fill drops them, and b) they were duplicated anyway, which xtable wouldn’t like.

    SOV <- unlist(lapply(1:length(summary(mod)), 
      function(x) rownames(unclass(summary(mod)[[x]])[[1]]))
    
    print(xtable(cbind(SOV, aovtab), include.rownames=F)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.