[R] Rounding behavior
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 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 On Behalf Of Ek Esawi > > Sent: Tuesday, October 9, 2018 3:44 PM > > To: r-help@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@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@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@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.
Re: [R] Rounding behavior
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 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]] __ R-help@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.
Re: [R] Mixed Beta Disrubutions
Smug, self-satisfied responses are becoming more common as exemplified here. These contribute to nothing except the author's ego and distract from the generous and patient help others provide. Regardless of how naive the questioner or how well-credentialed the respondent, the community would benefit if the sources of such comments found other outlets for condescension. Ryan Derickson > On Dec 28, 2015, at 10:32 PM, mesude bayrakci > wrote: > > Hello all, > > This would be my last comments on "politeness" discussion started after my > email, and do not want to keep the forum busy with this. Please do not > continue writing on this matter to the forum. > > First of all, I just started using R for a short period of time, and using > it for a small part of my research, given that I am coming from different > technical background. > 1) It is my understanding that the some of experts on this forum are > expecting high quality questions from people who have just started learning > things 2) It seems that Rolf's email has custom "cheer" signature. 3) In my > first email, I thank him for his response and tried to explain him that I > am aware of that example and did not think it would help me and thus asked > second question and did not claim that he would not answer my question, my > second response to Rolf's email was just basically reaction to his first > paragraph. 4) I think Oliver's comment is the most important one among the > points I stated here. > > Thank you for your support and suggestions, Oliver. It is greatly > appreciated. > > Thank you for your response, Jim. > > Best, > > Mesude > > >> On Mon, Dec 28, 2015 at 9:58 PM, Jim Lemon wrote: >> >> Hi mesude, >> Achim's example seems particularly clear. Install the "betareg" and >> "flexmix" packages. I obtain a reasonable looking result for alpha and beta >> for a simulated dataset very similar to yours. >> >>> a >>Comp.1 Comp.2 >> 10.0674445 0.6452801 >>> b >> Comp.1 Comp.2 >> 2.830934 0.769768 >> >> Jim >> >> >> On Tue, Dec 29, 2015 at 6:40 AM, mesude bayrakci >> wrote: >> >>> Hello, >>> >>> I have data; one column and 310 rows. When I plot the histogram, it has >>> two >>> peaks; please see the attachment. I would like to find appropriate >>> distribution that fits the data. I tried to mixtools in R, but it did not >>> fit well. >>> >>> I want to mix two beta distribution. I found that there is betareg package >>> in R but the shape1,shape2 were known or there were two different data in >>> the all examples. >>> >>> I do not know where to start. How can I use betamix in R to fit the data? >>> Any hint? >>> >>> I really appreciate. >>> >>> >>> Thank you >>> >>> __ >>> R-help@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@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. __ R-help@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.
Re: [R] subsetting
A combination of subsetting and ?substr should get you close to a solution. If the middle sequence you referenced isn't always the same distance from the first character, you may have to involve regular expressions to find "the middle". On Wednesday, February 24, 2016, Bert Gunter wrote: > Have you gone through any R tutorials yet? I didn't entirely > understand your question (and so cannot answer), but this sounds like > a basic subsetting/data wrangling task that you should know how to do > if you have gone through a basic tutorial or two. > > See also ?subset, ?"[" (basic indexing) and possibly also the plyR, > dplyr, or data.table packages that provide what some consider more > convenient and/or faster interfaces to these sorts of tasks. > > See also: http://vita.had.co.nz/papers/tidy-data.pdf > > for a nice article on "tidying" data (using plyr/dplyr). > > > > Cheers, > Bert > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Wed, Feb 24, 2016 at 6:57 PM, Val > > wrote: > > Hi all, > > > > One of the the columns of a data frame has a value such like > > > > S-2001-yy > > S-2004-xx > > F-2007-SS > > and so on > > > > based on this column (variable) I want subset a data frame where the > > middle value of this variable is between 2001 to 2004. > > THE END RESULT THE DATA FRAME WILL BE THIS. > > > > S-2001-yy > > S-2004-xx > > > > > > THANK YOU IN ADVANCE > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@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. > > __ > R-help@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@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.
Re: [R] subsetting a dataframe
Lots of ways to do this, I use %in% with bracket notation [row, column]. The empty column argument below returns all columns but you could have conditional logic there as well. dd[dd$rows %in% test_rows, ] On Mon, Jun 8, 2015 at 6:44 PM, Bogdan Tanasa wrote: > Dear all, > > would appreciate your suggestions on subsetting a dataframe : please let's > consider an example dataframe df: > > dd<-c(1,2,3) > rows<-c("A1","A2","A3") > columns<-c("B1","B2","B3") > numbers <- c(400, 500, 600) > df <- dataframe(dd,rows,columns, numbers) > > and a vector : test_rows <-c("A1","A3") ; > > how could I subset the dataframe df function of vector test_rows, in such a > way that only the lines of dataframe df (df$rows) that match the elements > of test_rows ("A1" and "A3") are listed ? > > thank you very much, > > -- bogdan > > [[alternative HTML version deleted]] > > __ > R-help@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@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.
[R] Specifying plot area in dotchart2
Hello, I'm producing multiple dotcharts and I want each plotting area (the area containing the dots only- not the labels) to be the same width. Currently, the width of the area depends on the length of the labels. I've tried different margin arguments but they change the parameter of the whole plot (dots + labels) rather than just the dot area. A reproducible example is below; I want the dot area to be the same physical width across charts regardless of the label width. Any suggestions would be greatly appreciated! Ryan Derickson library(Hmisc) pdf("dotchart2 demo.pdf") # This plot width is wider par(omi=c(0, 2, 0, 0), mar=c(2,4,1,1)) num<-rnorm(40, 0, 1) lab<-paste(rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2) ,rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2), sep="") dat<-data.frame(num, lab) dat<-dat[order(num),] dotchart2(dat$num, label=dat$lab, xlim=c(-3,3)) # This plot width is narrower par(omi=c(0, 2, 0, 0), mar=c(2,4,1,1)) num<-rnorm(40, 0, 1) lab<-paste(rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2), sep="") dat<-data.frame(num, lab) dat<-dat[order(num),] dotchart2(dat$num, label=dat$lab, xlim=c(-3,3)) dev.off() [[alternative HTML version deleted]] __ R-help@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.