peter dalgaard
2015-Nov-17 21:57 UTC
[R] Strange result when subsetting a data frame based on a character variable
> 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
David L Carlson
2015-Nov-17 23:03 UTC
[R] Strange result when subsetting a data frame based on a character variable
The conversion seems to be controlled by the scipen setting:> options("scipen")$scipen [1] 0> as.character(100000)[1] "1e+05"> options(scipen=5) > as.character(100000)[1] "100000"> as.character(1000000)[1] "1000000"> as.character(10000000)[1] "10000000" ------------------------------------- David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of peter dalgaard Sent: Tuesday, November 17, 2015 3:57 PM To: Bert Gunter Cc: r-help Subject: Re: [R] Strange result when subsetting a data frame based on a character variable> 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 ______________________________________________ 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.
Bert Gunter
2015-Nov-18 00:11 UTC
[R] Strange result when subsetting a data frame based on a character variable
Thanks, David. Probably as one should expect. But reinforces what others said about first doing explicit conversions so that comparisons are not made made between differing types. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Tue, Nov 17, 2015 at 3:03 PM, David L Carlson <dcarlson at tamu.edu> wrote:> The conversion seems to be controlled by the scipen setting: > >> options("scipen") > $scipen > [1] 0 >> as.character(100000) > [1] "1e+05" >> options(scipen=5) >> as.character(100000) > [1] "100000" >> as.character(1000000) > [1] "1000000" >> as.character(10000000) > [1] "10000000" > > ------------------------------------- > David L Carlson > Department of Anthropology > Texas A&M University > College Station, TX 77840-4352 > > > -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of peter dalgaard > Sent: Tuesday, November 17, 2015 3:57 PM > To: Bert Gunter > Cc: r-help > Subject: Re: [R] Strange result when subsetting a data frame based on a character variable > > >> 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 > > ______________________________________________ > 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.
Jeff Newmiller
2015-Nov-18 00:59 UTC
[R] Strange result when subsetting a data frame based on a character variable
Are you sure that wasn't oh-3 rather than 03? --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. On November 17, 2015 1:57:15 PM PST, peter dalgaard <pdalgd at gmail.com> wrote:> >> 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
2015-Nov-18 01:11 UTC
[R] Strange result when subsetting a data frame based on a character variable
> On 18 Nov 2015, at 01:59 , Jeff Newmiller <jdnewmil at dcn.davis.CA.us> wrote: > > Are you sure that wasn't oh-3 rather than 03?Sure I'm sure. I even cut+pasted the filenames from the offending dir... It's all just Apple trying to be helpful (and failing, again). O2 < 2d < O3 had been even stranger, no? -p> --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > Sent from my phone. Please excuse my brevity. > > On November 17, 2015 1:57:15 PM PST, peter dalgaard <pdalgd at gmail.com> wrote: >> >>> 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