Hello, Apologies if this is a simple misunderstanding. round((.575*100),0) gives 57 round(57.5,0) gives 58 Why? Ryan Derickson University of Cincinnati On Tue, Oct 9, 2018, 10:08 AM PIKAL Petr <petr.pikal at precheza.cz> wrote:> Hi > > You could use brute force approach. Just print out "file.names" and > estimate ordering vector. > In czech locale it is > > oo <- c(6, 11, 1, 4, 5, 2, 3, 10, 12, 9, 7, 8) > > In english locale it is different :-) > > After that > file.names[oo] > > should give you correct order of file names > > Cheers > Petr > > > -----Original Message----- > > From: R-help <r-help-bounces at r-project.org> On Behalf Of Ek Esawi > > Sent: Tuesday, October 9, 2018 3:44 PM > > To: r-help at r-project.org > > Subject: [R] Reorder file names read by list.files function > > > > Hi All-- > > > > I used base R list.file function to read files from a directory. The > file names are > > months (April, August, etc). That's the system reads them in > alphabetical order., > > but i want to reordered them in calendar order (January, February, > > ...December).. I thought i might be able to do it via RegEx or possibly > gtools > > package, I am wondering if there is an easier way. > > > > Thanks--EK > > > > Example > > path = "C:/Users/name/Downloads/MyFiles" > > file.names <- dir(path, pattern =".PDF") > > > > Example output > > Output: > > "February.PDF" "January.PDF" "March.PDF" > > Desired output > > "January.PDF" "February.PDF" "March.PDF" > > > > ______________________________________________ > > 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. > Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch > partner? PRECHEZA a.s. jsou zve?ejn?ny na: > https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information > about processing and protection of business partner?s personal data are > available on website: > https://www.precheza.cz/en/personal-data-protection-principles/ > D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou > d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? > odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any > documents attached to it may be confidential and are subject to the legally > binding disclaimer: https://www.precheza.cz/en/01-disclaimer/ > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
FAQ 7.31 Open this file in your favorite text editor on your computer system.file("../../doc/FAQ") 57.5 comes out even in binary, and .575 does not.> print(.575*100, digits=17)[1] 57.499999999999993 ## The fraction is less than .5, hence it gets rounded down to 57> print(57.5, digits=17)[1] 57.5 ## the fraction is exactly .5, hence gets rounded to the nearest even number 58 l On Tue, Oct 9, 2018 at 1:14 PM, Ryan Derickson <rlderickson at gmail.com> wrote:> Hello, > > Apologies if this is a simple misunderstanding. > > round((.575*100),0) gives 57 > round(57.5,0) gives 58 > > Why? > > Ryan Derickson > University of Cincinnati > > On Tue, Oct 9, 2018, 10:08 AM PIKAL Petr <petr.pikal at precheza.cz> wrote: > >> Hi >> >> You could use brute force approach. Just print out "file.names" and >> estimate ordering vector. >> In czech locale it is >> >> oo <- c(6, 11, 1, 4, 5, 2, 3, 10, 12, 9, 7, 8) >> >> In english locale it is different :-) >> >> After that >> file.names[oo] >> >> should give you correct order of file names >> >> Cheers >> Petr >> >> > -----Original Message----- >> > From: R-help <r-help-bounces at r-project.org> On Behalf Of Ek Esawi >> > Sent: Tuesday, October 9, 2018 3:44 PM >> > To: r-help at r-project.org >> > Subject: [R] Reorder file names read by list.files function >> > >> > Hi All-- >> > >> > I used base R list.file function to read files from a directory. The >> file names are >> > months (April, August, etc). That's the system reads them in >> alphabetical order., >> > but i want to reordered them in calendar order (January, February, >> > ...December).. I thought i might be able to do it via RegEx or possibly >> gtools >> > package, I am wondering if there is an easier way. >> > >> > Thanks--EK >> > >> > Example >> > path = "C:/Users/name/Downloads/MyFiles" >> > file.names <- dir(path, pattern =".PDF") >> > >> > Example output >> > Output: >> > "February.PDF" "January.PDF" "March.PDF" >> > Desired output >> > "January.PDF" "February.PDF" "March.PDF" >> > >> > ______________________________________________ >> > 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. >> Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch >> partner? PRECHEZA a.s. jsou zve?ejn?ny na: >> https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information >> about processing and protection of business partner?s personal data are >> available on website: >> https://www.precheza.cz/en/personal-data-protection-principles/ >> D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou >> d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? >> odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any >> documents attached to it may be confidential and are subject to the legally >> binding disclaimer: https://www.precheza.cz/en/01-disclaimer/ >> >> ______________________________________________ >> 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. >> > > [[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.
Floating point numbers are approximations in base 2, so any fractions not representing such numbers may round off in unexpected directions. sprintf( "%22.20f", 0.5 ) sprintf( "%22.20f", 0.575 ) See R FAQ 7.31. On October 9, 2018 10:14:54 AM PDT, Ryan Derickson <rlderickson at gmail.com> wrote:>Hello, > >Apologies if this is a simple misunderstanding. > >round((.575*100),0) gives 57 >round(57.5,0) gives 58 > >Why? > >Ryan Derickson >University of Cincinnati > >On Tue, Oct 9, 2018, 10:08 AM PIKAL Petr <petr.pikal at precheza.cz> >wrote: > >> Hi >> >> You could use brute force approach. Just print out "file.names" and >> estimate ordering vector. >> In czech locale it is >> >> oo <- c(6, 11, 1, 4, 5, 2, 3, 10, 12, 9, 7, 8) >> >> In english locale it is different :-) >> >> After that >> file.names[oo] >> >> should give you correct order of file names >> >> Cheers >> Petr >> >> > -----Original Message----- >> > From: R-help <r-help-bounces at r-project.org> On Behalf Of Ek Esawi >> > Sent: Tuesday, October 9, 2018 3:44 PM >> > To: r-help at r-project.org >> > Subject: [R] Reorder file names read by list.files function >> > >> > Hi All-- >> > >> > I used base R list.file function to read files from a directory. >The >> file names are >> > months (April, August, etc). That's the system reads them in >> alphabetical order., >> > but i want to reordered them in calendar order (January, February, >> > ...December).. I thought i might be able to do it via RegEx or >possibly >> gtools >> > package, I am wondering if there is an easier way. >> > >> > Thanks--EK >> > >> > Example >> > path = "C:/Users/name/Downloads/MyFiles" >> > file.names <- dir(path, pattern =".PDF") >> > >> > Example output >> > Output: >> > "February.PDF" "January.PDF" "March.PDF" >> > Desired output >> > "January.PDF" "February.PDF" "March.PDF" >> > >> > ______________________________________________ >> > 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. >> Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? >obchodn?ch >> partner? PRECHEZA a.s. jsou zve?ejn?ny na: >> https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information >> about processing and protection of business partner?s personal data >are >> available on website: >> https://www.precheza.cz/en/personal-data-protection-principles/ >> D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou >> d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? >> odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and >any >> documents attached to it may be confidential and are subject to the >legally >> binding disclaimer: https://www.precheza.cz/en/01-disclaimer/ >> >> ______________________________________________ >> 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. >> > > [[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.-- Sent from my phone. Please excuse my brevity.
Hello, On Tue, Oct 09, 2018 at 01:14:54PM -0400, Ryan Derickson wrote:> Apologies if this is a simple misunderstanding.See for example: https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f> round((.575*100),0) gives 57 > round(57.5,0) gives 58 > > Why?Not R related at all. $ python Python 2.7.13 (default, Sep 26 2018, 18:42:22) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information.>>> round((.575*100),0)57.0>>> round(57.5,0)58.0 Same "issue". :) You'll need to dig into how numbers are floating numbers are represented in a finite set. Cheers, -- Beno?t Vaillant -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 866 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20181009/0b862d59/attachment-0002.sig>
I thought it might be a floating issue but didn't see the connection. Thanks everyone. On Tue, Oct 9, 2018, 2:00 PM Benoit Vaillant <benoit.vaillant at no-log.org> wrote:> Hello, > > On Tue, Oct 09, 2018 at 01:14:54PM -0400, Ryan Derickson wrote: > > Apologies if this is a simple misunderstanding. > > See for example: > > https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f > > > round((.575*100),0) gives 57 > > round(57.5,0) gives 58 > > > > Why? > > Not R related at all. > > $ python > Python 2.7.13 (default, Sep 26 2018, 18:42:22) > [GCC 6.3.0 20170516] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> round((.575*100),0) > 57.0 > >>> round(57.5,0) > 58.0 > > Same "issue". :) > > You'll need to dig into how numbers are floating numbers are > represented in a finite set. > > Cheers, > > -- > Beno?t Vaillant >[[alternative HTML version deleted]]