On Sun, 1 Mar 2009, Gregory Propf wrote:

How does one write formatted, say "C style", output to a text file. I want something like "y=mx+b" for my linear regressions but with m and b derived from the fit objects. Also, how does one go about extracting just the slope or intercept from such an object. - Greg


Following the __posting guide__ should have gotten you through this. viz.

        ??format ## leads to sprintf
        ?lm      ## See Also coef
        ?coef    ## "Extract Model Coefficients"
        ??file   ## leads to sink
        ?sink    ## "Send R Output to a File"

e.g.


coefs <- coef( lm(rnorm(10)~I(1:10)) ) ## for example
sprintf( "y = %5.2fx%+5.2f", coefs[2], coefs[1] )
[1] "y = -0.08x+0.50"
sink("myFile.txt")
sprintf( "y = %5.2fx%+5.2f", coefs[2], coefs[1] )
sink()

Chuck






        [[alternative HTML version deleted]]

______________________________________________
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.


Charles C. Berry                            (858) 534-2098
                                            Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu               UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

______________________________________________
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.

Reply via email to