[R] Strange result when subsetting a data frame based on a character variable
peter dalgaard
pdalgd at gmail.com
Tue Nov 17 22:57:15 CET 2015
> On 17 Nov 2015, at 20:37 , Bert Gunter <bgunter.4567 at gmail.com> wrote:
>
>> 2 == "2"
> [1] TRUE
>
> ?"==" says:
>
> "If the two arguments are atomic vectors of different types, one is
> coerced to the type of the other, the (decreasing) order of precedence
> being character, complex, numeric, integer, logical and raw."
>
>> as.character(99999)
> [1] "99999"
>> as.character(100000)
> [1] "1e+05"
>> as.character(100000) == "100000"
> [1] FALSE
>
Also notice that, for similar reasons
> 10 > "2"
[1] FALSE
(At least in most collations. I recently discovered that OSX Finder sorted 2dnorm.R between 02-Probability.toc and 03-Combinatorics-2x2.pdf.)
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list