本文介绍了rmarkdown 表的单个单元格中的多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 RMarkdown 创建一个在单个单元格中有多行的表格.此页面提到了多行和网格表格单元格 (http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html).但似乎反斜杠不起作用.

I would like to create a table which has multiple lines in a single cell using RMarkdown. This page mentions multiline and grid table cells (http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html). But it seems backslash is not working.

A backslash followed by a newline is also a hard line break. 
Note: in multiline and grid table cells, this is the only way 
to create a hard line break, since trailing spaces in the cells are ignored.

这是我的示例 Rmd 文件.

This is my example Rmd file.

---
title: "Test"
author: "test"
date: "Tuesday, November 25, 2014"
output: html_document
---
Line 1 \  Line2  | Line 1 \  Line2
------------- | -------------
Line 1 \  Line2 | Line 1 \  Line2

是否有可能实现这一目标?感谢您的任何建议.

Is it possible to achieve this? Thanks for any suggestions.

这是我的 sessionInfo

This is my sessionInfo

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252   
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C                      
[5] LC_TIME=English_Australia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] digest_0.6.4     htmltools_0.2.6  rmarkdown_0.3.11 tools_3.1.1     

推荐答案

这是绝对可行的,参见 pander.CrossTable 使用这种方法:

It's absolutely doable, see eg pander.CrossTable using this approach:

> pander::pander(descr::CrossTable(mtcars$am, mtcars$gear))

----------------------------------------------------------------
   \     mtcars$gear\     \      \       \  
 mtcars$am         3             4           5          Total   
------------ -------------- ----------- ------------ -----------
  **0**\         \       \       \      \   
    N\           15\           4\           0\          19\     
Chi-square\    4.1694\       1.3706\     2.9688\         \      
  Row(%)\     78.9474%\     21.0526%\    0.0000%\    59.3750%\  
Column(%)\    100.0000%\    33.3333%\    0.0000%\         \     
  Total(%)      46.875%       12.500%      0.000%               

  **1**\         \       \       \      \   
    N\            0\           8\           5\          13\     
Chi-square\    6.0938\       2.0032\     4.3389\         \      
  Row(%)\      0.0000%\     61.5385%\   38.4615%\    40.6250%\  
Column(%)\     0.0000%\     66.6667%\   100.0000%\        \     
  Total(%)       0.000%       25.000%     15.625%               

   Total\         15\          12\          5\           32\    
                46.875%        37.5%      15.625%               
----------------------------------------------------------------

这篇关于rmarkdown 表的单个单元格中的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 18:54