Re: [R] Interquartile Range

2016-04-19 Thread Michael Artz
I already found a solution, you suggested I try to find a non hacky solution, which was not really my priority. I should have declined politely, which I will do now. Or, ifyou just want me to post reproducible code because you are bored or because you like solving problems then let me know and I wi

Re: [R] Interquartile Range

2016-04-19 Thread Bert Gunter
??? IQR returns a single number. > IQR(rnorm(10)) [1] 1.090168 To your 2nd response: "I could have used average, min, max, they all would have returned the same thing., " I can only respond: huh?? Are all your values identical? You really need to provide a small reproducible example as request

Re: [R] Interquartile Range

2016-04-19 Thread Michael Artz
Again, IQR returns two both a .25 and a .75 value and it failed, which is why I didn't use it before. Also, the first function just returns tha same value repeating. Since they are the same, before the second call, using the mode function is just a way to grab one value. I could have used average,

Re: [R] Interquartile Range

2016-04-19 Thread Marc Schwartz
Hi, Jumping into this thread mainly on the point of the mode of the distribution, while also supporting Bert's comments below on theory. If the vector 'x' that is being passed to this function is an integer vector, then a tabulation of the integers can yield a 'mode', presuming of course that

Re: [R] Interquartile Range

2016-04-19 Thread Bert Gunter
Well, instead of your functions try: Mode <- function(x) { tabx <- table(x) tabx[which.max(tabx)] } and use R's IQR function instead of yours. ... so I still don't get why you want to return a character string instead of a value for the IQR; and the mode of a sample defined as above is

Re: [R] Interquartile Range

2016-04-19 Thread Michael Artz
Hi, Here is what I am doing notGroupedAll <- ddply(data ,~groupColumn ,summarise ,col1_mean=mean(col1) ,col2_mode=Mode(col2) #Function I wrote for getting the mode shown below ,col3_Range=myIqr(col3)

Re: [R] Interquartile Range

2016-04-19 Thread William Dunlap via R-help
If you show us, not just tell us about, a self-contained example someone might show you a non-hacky way of getting the job done. (I don't see an argument to plyr::ddply called 'transform'.) Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Apr 19, 2016 at 12:18 PM, Michael Artz wrote: > Oh t

Re: [R] Interquartile Range

2016-04-19 Thread Michael Artz
Oh thanks for that clarification Bert! Hope you enjoyed your coffee! I ended up just using the transform argument in the ddply function. It worked and it repeated, then I called a mode function in another call to ddply that summarised. Kinda hacky but oh well! On Tue, Apr 19, 2016 at 12:31 PM,

Re: [R] Interquartile Range

2016-04-19 Thread Bert Gunter
... and I'm getting another cup of coffee... -- 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 Tue, Apr 19, 2016 at 10:30 AM, Bert Gunter wrote: > NO NO

Re: [R] Interquartile Range

2016-04-19 Thread Bert Gunter
NO NO -- I am wrong! The paste() expression is of course evaluated. It's just that a character string is returned of the form "something - something". I apologize for the confusion. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking thing

Re: [R] Interquartile Range

2016-04-19 Thread Bert Gunter
To be precise: paste(round(quantile(x,0.25),0),round(quantile(x,0.75),0),sep="-") is an expression that evaluates to a character string: "round(quantile(x,.25),0) - round(quantile(x,0.75),0)" no matter what the argument of your function, x. Hence return(paste(...)) will return this exact charac

Re: [R] Interquartile Range

2016-04-19 Thread William Dunlap via R-help
Can you show us a self-contained example, along with the output of running conflicts()? Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Apr 19, 2016 at 8:57 AM, Michael Artz wrote: > HI that did not work for me either. The value I got returned from that > function was " - " :(. thanks fo

Re: [R] Interquartile Range

2016-04-19 Thread Michael Artz
HI that did not work for me either. The value I got returned from that function was " - " :(. thanks for the reply through On Tue, Apr 19, 2016 at 10:34 AM, William Dunlap wrote: > > That didn't work Jim! > > It always helps to say how the suggestion did not work. Jim's > function had a typo

Re: [R] Interquartile Range

2016-04-19 Thread William Dunlap via R-help
> That didn't work Jim! It always helps to say how the suggestion did not work. Jim's function had a typo in it - was that the problem? Or did you not change the call to ddply to use that function. Here is something that might "work" for you: library(plyr) data <- data.frame(groupColumn=rep

Re: [R] Interquartile Range

2016-04-19 Thread Michael Artz
Hi bert, I understand the difference between a character string and a number. I need to return a character string, that is a requirement. It needs to be in that format. Getting the range with IQR is trivial I already tried it. The grouping function accepts only one return value, and IQR returns

Re: [R] Interquartile Range

2016-04-19 Thread Bert Gunter
Are you aware that there *already is* a function that does this? ?IQR (also your "function" iqr" is just a character string and would have to be parsed and evaluated to become a function. But this is a TERRIBLE way to do things in R as it completely circumvents R's central functional programming

Re: [R] Interquartile Range

2016-04-19 Thread Michael Artz
That didn't work Jim! Thanks anyway On Mon, Apr 18, 2016 at 9:02 PM, Jim Lemon wrote: > Hi Michael, > At a guess, try this: > > iqr<-function(x) { > return(paste(round(quantile(x,0.25),0),round(quantile(x,0.75),0),sep="-") > } > > .col3_Range=iqr(datat$tenure) > > Jim > > > > On Tue, Apr 19, 2

Re: [R] Interquartile Range

2016-04-18 Thread Jim Lemon
Hi Michael, At a guess, try this: iqr<-function(x) { return(paste(round(quantile(x,0.25),0),round(quantile(x,0.75),0),sep="-") } .col3_Range=iqr(datat$tenure) Jim On Tue, Apr 19, 2016 at 11:15 AM, Michael Artz wrote: > Hi, > I am trying to show an interquartile range while grouping values

[R] Interquartile Range

2016-04-18 Thread Michael Artz
Hi, I am trying to show an interquartile range while grouping values using the function ddply(). So my function call now is like groupedAll <- ddply(data ,~groupColumn ,summarise ,col1_mean=mean(col1) ,col2_mode=Mode(col2) #Fun