R-3.1.2> x <- factor(c("yes", "yes", "no", NA, "yes", "no", NaN)) > x[1] yes yes no <NA> yes no NaN Levels: NaN no yes> is.nan(x)[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE>From the above snippet can you notice that the "NaN" value is not logicallyidentified in a vector? Can anyone elaborate on this? Thank you for your effort! [[alternative HTML version deleted]]
On Dec 5, 2014, at 7:16 AM, Dinesh Chowdhary wrote:> R-3.1.2 > >> x <- factor(c("yes", "yes", "no", NA, "yes", "no", NaN)) >> x > [1] yes yes no <NA> yes no NaN > Levels: NaN no yes >> is.nan(x) > [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE > >> From the above snippet can you notice that the "NaN" value is not logically > identified in a vector? Can anyone elaborate on this?It gets converted to a character value. (As always... Read the help page.)> x <- factor(c("yes", "yes", "no", NA, "yes", "no", NaN), exclude=c(NA,NaN) ) > x[1] yes yes no <NA> yes no <NA> Levels: no yes> > Thank you for your effort! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius Alameda, CA, USA
'NaN' is a reserved keyword that implies 'Not a number'. I see
that you
use a character vector that includes 'NA' and 'NaN'. The former
'NA' is
considered as a missing value; however, the latter 'NaN' is considered
as a string 'NaN'. That's why three levels of 'NaN',
'no', 'yes' are
shown.
Function 'is.nan()' test if a numeric value is 'NaN'. Since you
are
using a character vector, the result of using 'is.nan()' should be all
FALSE.
If you wish to make R understand 'NaN' as missing value, it would be a
good choice to use reserved keyword 'NA_character' as shown in the
below:
> x <- factor(c("yes", "yes", "no", NA,
"yes", "no", NA_character_))
> x
[1] yes yes no <NA> yes no <NA>
Levels: no yes
> is.na(x)
[1] FALSE FALSE FALSE TRUE FALSE FALSE TRUE
I hope this helps.
Chel Hee Lee
On 12/5/2014 9:16 AM, Dinesh Chowdhary wrote:> R-3.1.2
>
>> x <- factor(c("yes", "yes", "no", NA,
"yes", "no", NaN))
>> x
> [1] yes yes no <NA> yes no NaN
> Levels: NaN no yes
>> is.nan(x)
> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>
>>From the above snippet can you notice that the "NaN" value is
not logically
> identified in a vector? Can anyone elaborate on this?
>
> Thank you for your effort!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>