Hi, I'm writing some R scripts and I would like to grab outputs from R functions to control if tests. Example, one function outputs something like "p-vale = 0.0765" and I want to program the following pseudo code in R sig = grep pvalue if (sig > 0.05) a() else b() Should I use the grep function of R (http://stat.ethz.ch/R-manual/R-devel/library/base/html/grep.html ) or is there other easy way to do it? Regards L?vio Cipriano
try this:> x <- "p-value = 0.0765" > sig <- as.numeric(sub(".*=(.*)", "\\1", x)) > > sig[1] 0.0765>On Mon, Aug 5, 2013 at 10:41 AM, Lívio Cipriano <lcmail4lists@gmail.com>wrote:> Hi, > > I'm writing some R scripts and I would like to grab outputs from R > functions > to control if tests. Example, one function outputs something like "p-vale > 0.0765" and I want to program the following pseudo code in R > > sig = grep pvalue > > if (sig > 0.05) > a() > else > b() > > Should I use the grep function of R ( > http://stat.ethz.ch/R-manual/R-devel/library/base/html/grep.html > ) or is there other easy way to do it? > > Regards > > Lívio Cipriano > > ______________________________________________ > R-help@r-project.org mailing list > 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]]
If you were to follow the recommendations in the footer of this email, you might
get some better options than using grep.
---------------------------------------------------------------------------
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.
"L?vio Cipriano" <lcmail4lists at gmail.com>
wrote:>Hi,
>
>I'm writing some R scripts and I would like to grab outputs from R
>functions
>to control if tests. Example, one function outputs something like
>"p-vale =
>0.0765" and I want to program the following pseudo code in R
>
>sig = grep pvalue
>
>if (sig > 0.05)
> a()
>else
> b()
>
>Should I use the grep function of R
>(http://stat.ethz.ch/R-manual/R-devel/library/base/html/grep.html
>) or is there other easy way to do it?
>
>Regards
>
>L?vio Cipriano
>
>______________________________________________
>R-help at r-project.org mailing list
>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.
On 05 August 2013 11:11:22 Phil Spector wrote:> but most functions in R > that provide p-values make it possible to extract the p-valuefrom the> result of the function call without using any textThanks for your answer. In fact it's the simple way to do it. Regards Lívio Cipriano [[alternative HTML version deleted]]