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?
Using your example:
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.The above drops the empty dimension. If you want to keep the table format, add
drop = FALSEto the call, though note the extra,in there as we want all columns hence the empty argument between, ,: