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 8334035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:13:05+00:00 2026-06-09T03:13:05+00:00

I have a two factor vectors v1 and v2 , which appear to be

  • 0

I have a two factor vectors v1 and v2, which appear to be closely related (the entropy of each is very close to their joint entropy). Indeed, when I do table(v1,v2), I see something like this:

     v2
 v1  a2   b2   c2
 a1  0    100   0
 b1  0    0     0
 c1  0    0     0
     v2 
 v1  d2   e2   f2
 a1  0    0     0
 b1  0    0     0
 c1  0    0     0

and so on – each factor has dozens of levels, so I get plenty of lines with all 0.

How to I print a table omitting lines which have only zeros in them?

  • 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-09T03:13:07+00:00Added an answer on June 9, 2026 at 3:13 am

    Using your example:

    v1 <- factor(rep("a1", 100), levels = paste0(letters[1:3], 1))
    v2 <- factor(rep("b2", 100), levels = paste0(letters[1:6], 2))
    
    R> table(v1, v2)
        v2
    v1    a2  b2  c2  d2  e2  f2
      a1   0 100   0   0   0   0
      b1   0   0   0   0   0   0
      c1   0   0   0   0   0   0
    

    Then the rowSums() function will compute the row sums for use. This works because a table is a either a vector or a matrix in disguise. Note in the sequence below showing intermediate steps how we convert the row sums into a logical vector by asking if they exceed 0.

    R> rowSums(tab)
     a1  b1  c1 
    100   0   0 
    R> rowSums(tab) > 0
       a1    b1    c1 
     TRUE FALSE FALSE 
    R> tab[rowSums(tab) > 0, ]
     a2  b2  c2  d2  e2  f2 
      0 100   0   0   0   0 
    

    The above drops the empty dimension. If you want to keep the table format, add drop = FALSE to the call, though note the extra , in there as we want all columns hence the empty argument between , ,:

    R> tab[rowSums(tab) > 0, , drop = FALSE]
        v2
    v1   a2  b2 c2 d2 e2 f2
      a1  0 100  0  0  0  0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Data Centers, each one with replication factor 3. Will write with
I have a two factor based authentication server which i need to integrate to
I have a scenario akin to a door lock which requires two-factor authentication to
I have two tables with the following (simplified) structures: table "Factors" which holds data
I have two classes (MVC view model) which inherits from one abstract base class.
I have two mixins which both convert to -webkit-transform : .rotate(@deg) { -webkit-transform: rotate(@deg);
I have two pieces of code I use often in which I use the
I have added Two Factor Authentication to my Mobile ASP.Net Web App. When the
I have two scripts which both generate random forests in R , which as
I have two vectors of integer. I would like to identify the intervals of

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.