Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"missing value where TRUE/FALSE needed" error vcd::mosaic

Tags:

r

> library(vcd)
Loading required package: MASS
Loading required package: grid
Loading required package: colorspace
> library(MASS)
> tbl = table(survey$W.Hnd,survey$Fold)
> print(tbl)

        L on R Neither R on L
  Left      10       1      7
  Right     88      17    113
> mosaic(tbl)
Error in if (split_vertical[i]) { : missing value where TRUE/FALSE needed
Calls: mosaic -> mosaic.default -> strucplot -> labeling
Execution halted

Why am I getting this error, and how to fix the code?


Easy paste code here:

library(vcd)
library(MASS)
tbl = table(survey$W.Hnd,survey$Fold) # survey is a library data set in MASS
print(tbl)
mosaic(tbl) # produces the above error
like image 783
yasar Avatar asked Jan 27 '13 12:01

yasar


2 Answers

Try this:

> mosaic(survey$W.Hnd ~ survey$Fold)

moasic

like image 195
Arun Avatar answered Oct 07 '22 16:10

Arun


Another option is to use structable from the vcd package itself.

library(vcd)
library(MASS)
tbl <- structable(survey$W.Hnd ~ survey$Fold)
print(tbl)
mosaic(tbl)
like image 43
Johan Larsson Avatar answered Oct 07 '22 15:10

Johan Larsson