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

  • SEARCH
  • Home
  • 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 7898831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:32:31+00:00 2026-06-03T08:32:31+00:00

I am trying to create a data.frame where some cells have missing values. Instead

  • 0

I am trying to create a data.frame where some cells have missing values. Instead of showing NAs, I wonder if there is any way to hide the NAs? What I want essentially is like an ANOVA table as shown below.

 x = rnorm(40)    
 y = rep(1:2, each=20)    
 z = rep(c(1,2,1,2), each=10)  
 model1 = lm(x~y * z)  
 model2 = lm(x~y + z)  
 anova(model1, model2)  

 #Analysis of Variance Table
 #Model 1: x ~ y * z
 #Model 2: x ~ y + z
 #Res.Df    RSS Df Sum of Sq      F Pr(>F)
 #1     36 38.931                           
 #2     37 39.248 -1  -0.31705 0.2932 0.5915

The output is above. If you try to access those blank cells, you will get NAs

 anova(model1, model2)[1,4]
 #[1] NA

Thanks in advance!!

  • 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-06-03T08:32:32+00:00Added an answer on June 3, 2026 at 8:32 am

    print.anova works by using the na.print option of print.default, like this:

    > x <- matrix(c(101:111/100, NA), nrow=3)
    > print(x, na.print="")
         [,1] [,2] [,3] [,4]
    [1,] 1.01 1.04 1.07 1.10
    [2,] 1.02 1.05 1.08 1.11
    [3,] 1.03 1.06 1.09     
    

    However, this only works for matrices, not for data frames.

    For data frames, the suggestion of replacing the NA’s with “” is good, but loses the usual printing of digits; you can do so by using format.data.frame before replacement. Read the print.data.frame function for more details. Doing it this way, you can also replace with NA and then use the na.print option, as above.

    > y <- as.data.frame(x)
    > m <- as.matrix(format.data.frame(y, digits = NULL, na.encode = FALSE))
    > m[is.na(y)] <- NA
    > print(m, na.print="", quote=FALSE)
      V1   V2   V3   V4  
    1 1.01 1.04 1.07 1.10
    2 1.02 1.05 1.08 1.11
    3 1.03 1.06 1.09   
    

    See how the digits in the fourth column line up? Compare to this.

    > z <- y
    > z[is.na(z)] <- ""
    > print(z)
        V1   V2   V3   V4
    1 1.01 1.04 1.07  1.1
    2 1.02 1.05 1.08 1.11
    3 1.03 1.06 1.09     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data.frame and I'm trying to create a frequency table that shows
I am trying to create some charts of data (eg http://www.amibroker.com/ ). Is there
I am trying create a data.frame from which to create a graph. I have
I'm trying to create core data application. Some times when trying to save data,
The task: I am trying to create a custom data type and have it
I am trying to create some dynamic html out of some data from db.
I'm trying to create a subset of a data frame and when I do
I am trying to use the structure() function to create a data frame in
I have a data frame and I'm trying to take a factor variable and
I have the following data and am trying to create a barplot in R

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.