Skip to content

How to write out this regression equation in R?

3 messages · liang.che at us.pwc.com, S Ellison, Jeff Newmiller

#
Maybe ?sprintf would help?

And if you wrap that in a function that takes a vector, using apply() on the table would give you one string per row,

*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
#
But sprintf is itself vectorized. If you give it vectors, it returns vectors. So you could obtain that apply-result more efficiently by passing a bunch of column vectors of data. There happens to be a convenient object called a data frame that holds a bunch of similar-length vectors.

DF <- data.frame( m=c(1,2), b=c(-3,4) )
result <- sprintf( "y=(%d)*x+(%d)", DF$m, DF$b)
cat(paste(result, collapse="\n"))

---------------------------------------------------------------------------
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.
S Ellison <S.Ellison at LGCGroup.com> wrote: