[R] How to include NA's of a factor in table?

Heinz Tuechler tuechler at gmx.at
Mon Jul 10 15:31:54 CEST 2006


Thank you Jacques and Gabor!

Your solution does work and it led me to try also:

table(factor(fcv, exclude=NULL))  # shows a, c, NA 

Greetings,
Heinz



At 08:34 10.07.2006 -0400, Gabor Grothendieck wrote:
>If we specify exclude=NULL in factor then it need not also be
>specified in table:
>
>fcv <- factor(c('a', NA, 'c'), exclude=NULL)
>table(fcv)
>
>
>
>On 7/10/06, Jacques VESLOT <jacques.veslot at good.ibl.fr> wrote:
>> fcv <- factor(c('a', NA, 'c'), exclude=NULL)
>> table(fcv, exclude=NULL)
>> -------------------------------------------------------------------
>> Jacques VESLOT
>>
>> CNRS UMR 8090
>> I.B.L (2ème étage)
>> 1 rue du Professeur Calmette
>> B.P. 245
>> 59019 Lille Cedex
>>
>> Tel : 33 (0)3.20.87.10.44
>> Fax : 33 (0)3.20.87.10.31
>>
>> http://www-good.ibl.fr
>> -------------------------------------------------------------------
>>
>>
>> Heinz Tuechler a écrit :
>> > Dear All,
>> >
>> > Is there a better way to include NA's of a factor in the output of
table()
>> > than using as.character()?
>> > Admittedly, I do not understand the help page for table concerning the
>> > exclude argument applied to factors. I tried in different ways, but could
>> > not get NA to be included in the table, if not using as.character() (see
>> > example).
>> >
>> > Greetings,
>> > Heinz
>> >
>> > ## example
>> > fcv <- factor(c('a', NA, 'c'))
>> > table(fcv)                # shows a, c
>> > table(fcv, exclude='a')   # shows c
>> > table(fcv, exclude="")    # shows a, c
>> > table(fcv, exclude=NULL)  # shows a, c
>> > table(as.character(fcv), exclude=NULL) # shows a, c, NA
>> >
>> > platform       i386-pc-mingw32
>> > arch           i386
>> > os             mingw32
>> > system         i386, mingw32
>> > status         Patched
>> > major          2
>> > minor          3.1
>> > year           2006
>> > month          07
>> > day            01
>> > svn rev        38471
>> > language       R
>> > version.string Version 2.3.1 Patched (2006-07-01 r38471)
>> >
>> > ______________________________________________
>> > R-help at stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>> >
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>>
>
>



More information about the R-help mailing list