Hello! I have a dataset with NA's in some variables (factors), for example: $ P67 : Factor w/ 2 levels "-","+": NA 2 1 NA NA 2 1 1 2 NA ... I need to use 'xtabs' like xtabs(~x$P67) It works well and produces something like this: x$P67 - + 779 1318 but i want to compute NA's too, like this: x$P67 - + NA 779 1318 137 I am trying xtabs(~x$P67, exclude=NULL) but xtabs does not compute 'NA's in this case too. I do not want to transform my data (do not want to do any substitution on NA's). How i can say 'xtabs' to compute NA-values? and second question: how to use argument 'na.action' in 'xtabs'? 'xtabs' help page does not explain this. Thanks!
Kosenkov Kirill wrote:> Hello! > > I have a dataset with NA's in some variables (factors), for example: > $ P67 : Factor w/ 2 levels "-","+": NA 2 1 NA NA 2 1 1 2 NA ... >The key is here. Should be 3 levels if you want NAs included.> I need to use 'xtabs' like > xtabs(~x$P67) > It works well and produces something like this: > x$P67 > - + > 779 1318 > but i want to compute NA's too, like this: > x$P67 > - + NA > 779 1318 137 > > I am trying xtabs(~x$P67, exclude=NULL) but xtabs does not compute 'NA's > in this case too. > > I do not want to transform my data (do not want to do any substitution > on NA's). > > How i can say 'xtabs' to compute NA-values? > > and second question: how to use argument 'na.action' in 'xtabs'? > 'xtabs' help page does not explain this. > > Thanks! >Try this: x$P67 = factor(x$P67, exclude = NULL) xtabs(~x$P67) Here's an example: R> x = factor(c(1:2, NA), exclude = NULL, labels = c("+", "-", "0")) R> xtabs(~ x) x + - 0 1 1 1 Sundar
Hi On 15 May 2003 at 0:18, Kosenkov Kirill wrote:> Hello! > > I have a dataset with NA's in some variables (factors), for example: $ > P67 : Factor w/ 2 levels "-","+": NA 2 1 NA NA 2 1 1 2 NA ... > > I need to use 'xtabs' like > xtabs(~x$P67) > It works well and produces something like this: > x$P67 > - + > 779 1318 > but i want to compute NA's too, like this: > x$P67 > - + NA > 779 1318 137what about using summary instead of xtabs> summary(ostbet$delka)159 160 NA's 5 22 3> xtabs(~ostbet$delka)ostbet$delka 159 160 5 22> > I am trying xtabs(~x$P67, exclude=NULL) but xtabs does not compute > 'NA's in this case too. > > I do not want to transform my data (do not want to do any > substitution on NA's). > > How i can say 'xtabs' to compute NA-values? > > and second question: how to use argument 'na.action' in 'xtabs'? > 'xtabs' help page does not explain this. > > Thanks! > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-helpCheers Petr Pikal petr.pikal at precheza.cz p.pik at volny.cz