Hi, Some general questions. I want to build a web page with numerical analysis generated by R. I have a few questions: - Can I control the output of a function? For example, if I do:> summary(data[[5]])Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0 0.0 120.0 193.3 310.0 10290.0 can I control the output to be something like min=0 q1=0.0 q2=120.0 q3=193.3 max=10290.0 in order to parse with an external program? - Yet another question on histograms: can I produce them with character strings? I'm guessing I need to map each character value to a numerical one and use that instead. Thanks, L -- Laurent Duperval <laurent.duperval at microcell.ca> "My doctor told me to stop having intimate dinners for four. Unless there are three other people." - Orson Welles
The answer to your first question is yes, you can. Under the hood a call "summary(data[[5]])" invovles an implicit call to print() of the value returned by summary(). This print produces the output you see. So you need to suppress the default print and call one of your own, e.g.> x <- summary(data[[5]]) # no print since the returned value is assigned > my.custom.print(x)A caviat, R will try to print the value returned by my.custom.print. To suppress it the return value should be made invisible, e.g. put invisible(NULL) in the end of my.custom.print> -----Original Message----- > From: laurent.duperval at microcell.ca > [mailto:laurent.duperval at microcell.ca] > Sent: Wednesday, March 19, 2003 11:28 AM > To: R Help List > Subject: [R] Some more general questions > > > Hi, > > Some general questions. I want to build a web page with > numerical analysis > generated by R. I have a few questions: > > - Can I control the output of a function? For example, if I do: > > > summary(data[[5]]) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 0.0 0.0 120.0 193.3 310.0 10290.0 > > can I control the output to be something like > > min=0 > q1=0.0 > q2=120.0 > q3=193.3 > max=10290.0 > > in order to parse with an external program? > > - Yet another question on histograms: can I produce them with > character > strings? I'm guessing I need to map each character value to > a numerical > one and use that instead. > > Thanks, > > L > > -- > Laurent Duperval <laurent.duperval at microcell.ca> > > "My doctor told me to stop having intimate dinners for four. > Unless there are > three other people." > - Orson Welles > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >-------------------------------------------------- DISCLAIMER\ This e-mail, and any attachments thereto, is intende... [[dropped]]
For summary(), yes, you can alter the way things are displayed. It's easiest to think of capturing the output from summary() in a temporary variable, then displaying that variable's value, but this could also all be done as inline code. For example, temp <- summary(data[[5]]) print(cbind(names(temp), format(as.numeric(temp))), quote=F) Second question: calling hist() with a vector of character strings doesn't work, and arguably, it shouldn't. There's no intrinsic notion of "interval" for character strings, no sense in which you want to discretize continuous data into a set of contiguous, discrete "bins". Character strings are discrete already. So use barplot(table(data[[ ? ]])). (Can't remember which columns in your exampel would have string values.) Or temp <- table(data) and print the result however you want. - tom blackwell - u michigan medical school - ann arbor - On Wed, 19 Mar 2003 laurent.duperval at microcell.ca wrote:> Some general questions. > > - Can I control the output of a function? For example, if I do: > > summary(data[[5]]) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 0.0 0.0 120.0 193.3 310.0 10290.0 > > can I control the output to be something like > > min=0 > q1=0.0 > q2=120.0 > q3=193.3 > max=10290.0 > > in order to parse with an external program? > > - Yet another question on histograms: can I produce them with character > strings? I'm guessing I need to map each character value to a numerical > one and use that instead. >