[R] Export to LaTeX

Tobias Verbeke tobias.verbeke at gmail.com
Fri Jul 14 10:44:06 CEST 2006


Mag. Ferri Leberl wrote:
> Dear Everybody!
> I want to export data to LaTeX. As I want to employ the data as freely as 
> possible I want to avoid the xtable-command and instead generate some List 
> like
>
> \MyOwnPrettyCommand{Adam}{Auer}{17}
> \MyOwnPrettyCommand{Bertram}{Bauer}{14}
> \MyOwnPrettyCommand{Christoph}{Huber}{75}
> \MyOwnPrettyCommand{Damian}{Dorfer}{69}
> \MyOwnPrettyCommand{Emanuel}{Eder}{43}
>
> with \MyOwnPrittyCommand defined elsewhere.
> As a pitty, if I make up about such a table in r, lets call it "A", and use 
> the commands
>
> sink("tabelle.tex")
> A
> sink("anderedatei")
>
> tabelle.tex will look like this:
>
>      [,1]                  [,2]        [,3] [,4]     [,5] [,6] [,7]
> [1,] "MyOwnPrettyCommand{" "Adam"      "}{" "Auer"   "}{" "17" "}" 
> [2,] "MyOwnPrettyCommand{" "Bertram"   "}{" "Bauer"  "}{" "14" "}" 
> [3,] "MyOwnPrettyCommand{" "Christoph" "}{" "Huber"  "}{" "75" "}" 
> [4,] "MyOwnPrettyCommand{" "Damian"    "}{" "Dorfer" "}{" "69" "}" 
> [5,] "MyOwnPrettyCommand{" "Emanuel"   "}{" "Eder"   "}{" "43" "}" 
>
> So my question is how to export the data properly, without line-indices, 
> without quotes but WITH backslashes.
>   
mydf <- as.data.frame(
      rbind(c("Adam",      "Auer",   17),
      c("Bertram",   "Bauer",  14),
      c("Christoph", "Huber",  75),
      c("Damian",    "Dorfer", 69),
      c("Emanuel",   "Eder",   43))
      )
cat(
    paste("\\MyCommand{", mydf[,"V1"], "}{", mydf[,"V2"], "}{", 
mydf[,"V3"], "}",
          sep ="", collapse = "\n")
    , file = "tabelle.tex")

HTH,
Tobias
> Thank you in advance.
> Yours,
> Mag. Ferri Leberl
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>



More information about the R-help mailing list