Please help:
# I have a data frame x:
x <- data.frame(a = c(1:3, NA), b = c(NA, 2:4))
# I run a cross-tab keeping NAs, like this:
table(x[c("a", "b")], useNA = "ifany")
# I want to reproduce it using xtabs, but it ignores NAs:
xtabs(~ a + b, x)
# I can't figure out how to force xtabs to
Try both na.action=na.pass and exclude=NULL, the first is for
xtabs' call to model.frame and the second for when it prepares
the data from model.frame's output for a call to table.
xtabs(formula = ~a + b, data = x, na.action = na.pass, exclude = NULL)
Bill Dunlap
TIBCO Software
wdunlap tibco.com
: William Dunlap
Cc: r-help
Subject: Re: [R] na.action in xtabs - how to include NAs?
Thank you very much, Bill - it worked.
Wow, that's very wordy!
On Wed, Sep 30, 2015 at 11:09 AM, William Dunlap <wdun...@tibco.com> wrote:
> Try both na.action=na.pass and exclude=NULL, the first is
Thank you very much, Bill - it worked.
Wow, that's very wordy!
On Wed, Sep 30, 2015 at 11:09 AM, William Dunlap wrote:
> Try both na.action=na.pass and exclude=NULL, the first is for
> xtabs' call to model.frame and the second for when it prepares
> the data from model.frame's
4 matches
Mail list logo