On 22/02/2016 3:46 PM, Santosh wrote:> Just figured out.. > > as.data.frame(as.matrix(<tabular_object>),stringsAsFactors=F) > > could work! :)Why do you want to produce Markdown output? the tables package (lowercase t!) can produce output in either LaTeX or HTML. Just tell knitr to leave the output alone, e.g. for PDF output ```{r results="asis"} require(tables) tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) latex(tab) ``` or for HTML output ```{r results="asis"} require(tables) tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) html(tab) ``` Duncan Murdoch> > > On Mon, Feb 22, 2016 at 12:17 PM, Santosh <santosh2005 at gmail.com> wrote: > >> Dear Rxperts.. >> I am able to generate tables using Tables R package.. >> However, when I have been unsuccessful in using kable (from knitr package) >> to generate the table in R markdown script.. >> >> It's because the output generated by "tabular" in Tables package is of >> class "tabular". The kable function in knitr package accepts data.frame. >> >> Is there a way to convert the tabular class objects into data.frame >> objects? >> >> Or is there a way that kable can accept "tabular" class object? >> >> >> Thanks so much.. >> Santosh >> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >
Sorry.. I forgot to mention that I wanted it be published in MS Word, because it goes into a Report this is prepared using MS Word. Hence,the above effort.. yes, it's a lot easier to send it to Latex.. I was also wondering if it is possible to add "\hline" separating the categories in a table.. Using tabular, I get this: \begin{tabular}{lcccc} \hline "Name" & "Value1" & \multicolumn{1}{c}{"Value2"} \\ \hline \nopagebreak A1 & 0.06 & 1.2 \\ \nopagebreak A5 & 0.62 & 8.9 \\ \nopagebreak A6 & 0.48 & 4.2 \\ \rule{0pt}{1.7\normalbaselineskip}A2 & 1.50 & 1.27 \\ \nopagebreak A7 & 0.11 & 4.3 \\ \nopagebreak A3 & 0.01 & 3.1 \\ \rule{0pt}{1.7\normalbaselineskip}A4 & 2.19 & 1.0 \\ \nopagebreak B1. & 0.03 & 2.0 \\ \nopagebreak B2. & 0.011 & 1.8 \\ \rule{0pt}{1.7\normalbaselineskip}B3 & 0.10 & 2.7 \\ \nopagebreak B4. & 0.02 & 1.6 \\ \nopagebreak C1. & 0.01 & 1.1 \\ \hline \end{tabular} But, I want in this way.. (with horizontal lines and customized text inserted at the beginning of a group.. \begin{tabular}{lcccc} \hline "Name" & "Value1" & \multicolumn{1}{c}{"Value2"} \\ \hline \multicolumn{5}{l}{\textbf{Hardened}}\\ \hline \nopagebreak A1 & 0.06 & 1.2 \\ \nopagebreak \tA5 & 0.62 & 8.9 \\ \nopagebreak \tA6 & 0.48 & 4.2 \\ \rule{0pt}{1.7\normalbaselineskip}A2 & 1.50 & 1.27 \\ \nopagebreak \tA7 & 0.11 & 4.3 \\ \nopagebreak \tA3 & 0.01 & 3.1 \\ \rule{0pt}{1.7\normalbaselineskip}A4 & 2.19 & 1.0 \\ \hline \multicolumn{3}{l}{\textbf{Pulverized}}\\ \hline \nopagebreak B1. & 0.03 & 2.0 \\ \nopagebreak B2. & 0.011 & 1.8 \\ \rule{0pt}{1.7\normalbaselineskip}B3 & 0.10 & 2.7 \\ \nopagebreak B4. & 0.02 & 1.6 \\ \hline \multicolumn{3}{l}{\textbf{Molten}}\\ \hline \nopagebreak C1. & 0.01 & 1.1 \\ \hline \end{tabular} Thanks so much for your help! Santosh On Mon, Feb 22, 2016 at 1:55 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:> On 22/02/2016 3:46 PM, Santosh wrote: > >> Just figured out.. >> >> as.data.frame(as.matrix(<tabular_object>),stringsAsFactors=F) >> >> could work! :) >> > > Why do you want to produce Markdown output? the tables package (lowercase > t!) can produce output in either LaTeX or HTML. Just tell knitr to leave > the output alone, e.g. for PDF output > > ```{r results="asis"} > require(tables) > tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* > (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) > latex(tab) > ``` > > or for HTML output > > ```{r results="asis"} > require(tables) > tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* > (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) > html(tab) > ``` > > > Duncan Murdoch > > >> >> On Mon, Feb 22, 2016 at 12:17 PM, Santosh <santosh2005 at gmail.com> wrote: >> >> Dear Rxperts.. >>> I am able to generate tables using Tables R package.. >>> However, when I have been unsuccessful in using kable (from knitr >>> package) >>> to generate the table in R markdown script.. >>> >>> It's because the output generated by "tabular" in Tables package is of >>> class "tabular". The kable function in knitr package accepts data.frame. >>> >>> Is there a way to convert the tabular class objects into data.frame >>> objects? >>> >>> Or is there a way that kable can accept "tabular" class object? >>> >>> >>> Thanks so much.. >>> Santosh >>> >>> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> >> >[[alternative HTML version deleted]]
On Mon, Feb 22, 2016 at 1:55 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:> > On 22/02/2016 3:46 PM, Santosh wrote: >> >> Just figured out.. >> >> as.data.frame(as.matrix(<tabular_object>),stringsAsFactors=F) >> >> could work! :) > > > Why do you want to produce Markdown output? the tables package (lowercase t!) can produce output in either LaTeX or HTML. Just tell knitr to leave the output alone, e.g. for PDF output > > ```{r results="asis"} > require(tables) > tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* > (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) > latex(tab) > ``` > > or for HTML output > > ```{r results="asis"} > require(tables) > tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* > (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) > html(tab) > ```In case of you would rather generate markdown instead of HTML/LaTeX to be independent from the resulting output document format, you can give a try to the "pander" package, which can transform quite many R object types into markdown, eg: #> library(tables) #> tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* #+ (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) #> pander::pander(tab) ------------------------------------------------------------ \ \ Sepal.Length\ \ Sepal.Width\ \ Species n mean sd mean sd ------------ ---- ---------------- ---- --------------- ---- *setosa* 50 5.01 0.35 3.43 0.38 *versicolor* 50 5.94 0.52 2.77 0.31 *virginica* 50 6.59 0.64 2.97 0.32 *All* 150 5.84 0.83 3.06 0.44 ------------------------------------------------------------ Please find more details at http://rapporter.github.io/pander/#generic-pander-method, or the knitr+pander vignette at https://cran.rstudio.com/web/packages/pander/vignettes/knitr.html Best, Gergely> > > > > Duncan Murdoch > > >> >> >> On Mon, Feb 22, 2016 at 12:17 PM, Santosh <santosh2005 at gmail.com> wrote: >> >>> Dear Rxperts.. >>> I am able to generate tables using Tables R package.. >>> However, when I have been unsuccessful in using kable (from knitr package) >>> to generate the table in R markdown script.. >>> >>> It's because the output generated by "tabular" in Tables package is of >>> class "tabular". The kable function in knitr package accepts data.frame. >>> >>> Is there a way to convert the tabular class objects into data.frame >>> objects? >>> >>> Or is there a way that kable can accept "tabular" class object? >>> >>> >>> Thanks so much.. >>> Santosh >>> >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Thanks, Gergely.. I wonder if it allows to insert lines etc as sent in previous email.... which might need some additional preprocessing.. Best, Santosh On Mon, Feb 22, 2016 at 3:27 PM, Gergely Dar?czi <gergely at snowl.net> wrote:> On Mon, Feb 22, 2016 at 1:55 PM, Duncan Murdoch > <murdoch.duncan at gmail.com> wrote: > > > > On 22/02/2016 3:46 PM, Santosh wrote: > >> > >> Just figured out.. > >> > >> as.data.frame(as.matrix(<tabular_object>),stringsAsFactors=F) > >> > >> could work! :) > > > > > > Why do you want to produce Markdown output? the tables package > (lowercase t!) can produce output in either LaTeX or HTML. Just tell knitr > to leave the output alone, e.g. for PDF output > > > > ```{r results="asis"} > > require(tables) > > tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* > > (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) > > latex(tab) > > ``` > > > > or for HTML output > > > > ```{r results="asis"} > > require(tables) > > tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* > > (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) > > html(tab) > > ``` > > > In case of you would rather generate markdown instead of HTML/LaTeX to > be independent from the resulting output document format, you can give > a try to the "pander" package, which can transform quite many R object > types into markdown, eg: > > #> library(tables) > #> tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* > #+ (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) > #> pander::pander(tab) > > ------------------------------------------------------------ > \ \ Sepal.Length\ \ Sepal.Width\ \ > Species n mean sd mean sd > ------------ ---- ---------------- ---- --------------- ---- > *setosa* 50 5.01 0.35 3.43 0.38 > > *versicolor* 50 5.94 0.52 2.77 0.31 > > *virginica* 50 6.59 0.64 2.97 0.32 > > *All* 150 5.84 0.83 3.06 0.44 > ------------------------------------------------------------ > > Please find more details at > http://rapporter.github.io/pander/#generic-pander-method, or the > knitr+pander vignette at > https://cran.rstudio.com/web/packages/pander/vignettes/knitr.html > > Best, > Gergely > > > > > > > > > > > > Duncan Murdoch > > > > > >> > >> > >> On Mon, Feb 22, 2016 at 12:17 PM, Santosh <santosh2005 at gmail.com> > wrote: > >> > >>> Dear Rxperts.. > >>> I am able to generate tables using Tables R package.. > >>> However, when I have been unsuccessful in using kable (from knitr > package) > >>> to generate the table in R markdown script.. > >>> > >>> It's because the output generated by "tabular" in Tables package is of > >>> class "tabular". The kable function in knitr package accepts > data.frame. > >>> > >>> Is there a way to convert the tabular class objects into data.frame > >>> objects? > >>> > >>> Or is there a way that kable can accept "tabular" class object? > >>> > >>> > >>> Thanks so much.. > >>> Santosh > >>> > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> 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. > >> > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. >[[alternative HTML version deleted]]
On 22/02/2016 6:19 PM, Santosh wrote:> Sorry.. I forgot to mention that I wanted it be published in MS Word, > because it goes into a Report this is prepared using MS Word.I can't help you with that.> > Hence,the above effort.. yes, it's a lot easier to send it to Latex.. > > I was also wondering if it is possible to add "\hline" separating the > categories in a table.. > > Using tabular, I get this: > > \begin{tabular}{lcccc} > \hline > "Name" & "Value1" & \multicolumn{1}{c}{"Value2"} \\ > \hline > \nopagebreak A1 & 0.06 & 1.2 \\ > \nopagebreak A5 & 0.62 & 8.9 \\ > \nopagebreak A6 & 0.48 & 4.2 \\ > \rule{0pt}{1.7\normalbaselineskip}A2 & 1.50 & 1.27 \\ > \nopagebreak A7 & 0.11 & 4.3 \\ > \nopagebreak A3 & 0.01 & 3.1 \\ > \rule{0pt}{1.7\normalbaselineskip}A4 & 2.19 & 1.0 \\ > \nopagebreak B1. & 0.03 & 2.0 \\ > \nopagebreak B2. & 0.011 & 1.8 \\ > \rule{0pt}{1.7\normalbaselineskip}B3 & 0.10 & 2.7 \\ > \nopagebreak B4. & 0.02 & 1.6 \\ > \nopagebreak C1. & 0.01 & 1.1 \\ > \hline > \end{tabular} > > But, I want in this way.. (with horizontal lines and customized text > inserted at the beginning of a group.. >If you wanted LaTeX output, you could do this like the example at the end of section 2.1.5 in the vignette. (You might want to combine that with subsetting as in section 3.3.) Duncan Murdoch> \begin{tabular}{lcccc} > \hline > "Name" & "Value1" & \multicolumn{1}{c}{"Value2"} \\ > \hline > \multicolumn{5}{l}{\textbf{Hardened}}\\ > \hline > \nopagebreak A1 & 0.06 & 1.2 \\ > \nopagebreak \tA5 & 0.62 & 8.9 \\ > \nopagebreak \tA6 & 0.48 & 4.2 \\ > \rule{0pt}{1.7\normalbaselineskip}A2 & 1.50 & 1.27 \\ > \nopagebreak \tA7 & 0.11 & 4.3 \\ > \nopagebreak \tA3 & 0.01 & 3.1 \\ > \rule{0pt}{1.7\normalbaselineskip}A4 & 2.19 & 1.0 \\ > \hline > \multicolumn{3}{l}{\textbf{Pulverized}}\\ > \hline > \nopagebreak B1. & 0.03 & 2.0 \\ > \nopagebreak B2. & 0.011 & 1.8 \\ > \rule{0pt}{1.7\normalbaselineskip}B3 & 0.10 & 2.7 \\ > \nopagebreak B4. & 0.02 & 1.6 \\ > \hline > \multicolumn{3}{l}{\textbf{Molten}}\\ > \hline > \nopagebreak C1. & 0.01 & 1.1 \\ > \hline > \end{tabular} > > Thanks so much for your help! > Santosh > > On Mon, Feb 22, 2016 at 1:55 PM, Duncan Murdoch <murdoch.duncan at gmail.com> > wrote: > >> On 22/02/2016 3:46 PM, Santosh wrote: >> >>> Just figured out.. >>> >>> as.data.frame(as.matrix(<tabular_object>),stringsAsFactors=F) >>> >>> could work! :) >>> >> >> Why do you want to produce Markdown output? the tables package (lowercase >> t!) can produce output in either LaTeX or HTML. Just tell knitr to leave >> the output alone, e.g. for PDF output >> >> ```{r results="asis"} >> require(tables) >> tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* >> (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) >> latex(tab) >> ``` >> >> or for HTML output >> >> ```{r results="asis"} >> require(tables) >> tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* >> (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) >> html(tab) >> ``` >> >> >> Duncan Murdoch >> >> >>> >>> On Mon, Feb 22, 2016 at 12:17 PM, Santosh <santosh2005 at gmail.com> wrote: >>> >>> Dear Rxperts.. >>>> I am able to generate tables using Tables R package.. >>>> However, when I have been unsuccessful in using kable (from knitr >>>> package) >>>> to generate the table in R markdown script.. >>>> >>>> It's because the output generated by "tabular" in Tables package is of >>>> class "tabular". The kable function in knitr package accepts data.frame. >>>> >>>> Is there a way to convert the tabular class objects into data.frame >>>> objects? >>>> >>>> Or is there a way that kable can accept "tabular" class object? >>>> >>>> >>>> Thanks so much.. >>>> Santosh >>>> >>>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> 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. >>> >>> >> >