dcmpf: Convert number for table columns, for equations

Description Usage Arguments Value Note Author(s) Examples

Description

Convert number
- for use in decimal dot centered table columns: Replace "." in a number by "&" for LaTeX tables using column specification r\@{.}l.
- mpf(r,n) returns "+ r" or "- r", depending on the sign of r, with n decimal digits. Useful in Sweave files \*.Rnw for composing text for linear combinations with coefficients shown in \Sexp.

Usage

1
2
3
  dc (x,d,ch="&")
  dcn(x,d,ch="&")
  mpf(r,after)

Arguments

x

Numerical vector.

d

Number of decimals after ".". d >= 1, will be forced internally.

ch

Substitute "." by ch

after

See formatFix, the number of decimals after ".".

r

real value.

Value

string representation of x suitable for table column centered on "."

Note

dc = dcn, except for x = integer .

dc uses frac, dcn uses sprintf.

Author(s)

Christian W. Hoffmann <christian@echoffmann.ch>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
  nn <- c(0, 1, 0.1, pi,2*pi,-30*pi)
  dc(nn,3)    # "0&0"     "1&0"     "0&100"   "3&142"   "6&283"   "-94&248"
  dcn(nn,3)   # "0&000"   "1&000"   "0&100"   "3&142"   "6&283"   "-94&248"
  mpf(pi,5); mpf(-pi,5)  # "+ 3.14159" "- 3.14159"  Note the space after the sign.

#### In example file 'T.Rnw':
##  <<echo=TRUE>>=
a <- -2; b <- -4; c <- 7
##  @ 
##  
##  The coefficients are: $a = \Sexpr{a}$, $b = \Sexpr{b}$, $c = \Sexpr{c}$.
##  

##  For the linear combination $$z = a + bx +cy$$ we thenhave
##   $$z = \Sexpr{sprintf(%.4f,a)} \Sexpr{mpf(b,3)} x \Sexpr{mpf(c,5)} y$$
#### end T.Rnw
###  Sweave: T.Rnw .. T.tex .. T.dvi

cwhmisc documentation built on May 1, 2019, 7:55 p.m.