基本问题:如何将我打印的表格导出到R控制台并粘贴到文本编辑器(例如此对话框)中,保持适当的格式。考虑一下我想打印表格的头部:
> head(cytoplasmic)
我将在控制台中获得以下输出:
V1 V2 V3 V4 V5 V6
3 LdBPK_020440.1 cytoplasmic: 0.54 nuclear: 0.45 mitochondrial: 0.0 Golgi apparatus: 0.0 peroxisomal: 0.0
5 LdBPK_201720.1 cytoplasmic: 0.89 nuclear: 0.06 mitochondrial: 0.02 peroxisomal: 0.01 Golgi apparatus: 0.01
6 LdBPK_070130.1 cytoplasmic: 0.61 nuclear: 0.32 peroxisomal: 0.05 mitochondrial: 0.02 Golgi apparatus: 0.0
7 LdBPK_040060.1 cytoplasmic: 0.52 nuclear: 0.43 mitochondrial: 0.02 extracellular: 0.01 peroxisomal: 0.01
13 LdBPK_191560.1 cytoplasmic: 0.49 nuclear: 0.46 mitochondrial: 0.03 peroxisomal: 0.01 Golgi apparatus: 0.0
15 LdBPK_364730.1 cytoplasmic: 0.93 nuclear: 0.06 mitochondrial: 0.0 peroxisomal: 0.0 Golgi apparatus: 0.0
V7 V8 V9 V10
3 plasma membrane: 0.0 extracellular: 0.0 ER: 0.0 lysosomal: 0.0
5 extracellular: 0.0 plasma membrane: 0.0 ER: 0.0 lysosomal: 0.0
6 plasma membrane: 0.0 extracellular: 0.0 ER: 0.0 lysosomal: 0.0
7 Golgi apparatus: 0.01 plasma membrane: 0.0 ER: 0.0 lysosomal: 0.0
13 plasma membrane: 0.0 extracellular: 0.0 ER: 0.0 lysosomal: 0.0
15 extracellular: 0.0 plasma membrane: 0.0 ER: 0.0 lysosomal: 0.0
在这个文本对话框中根本没有合适的格式。
我还尝试使用knitr包中的kable函数,代码如下:
> kable(head(cytoplasmic, format = "markdown"))
然后我得到以下输出:
|V1 |V2 |V3 |V4 |V5 |V6 |V7 |V8 |V9 |V10 |
|:--|:--------------|:-----------------|:-------------|:-------------------|:--------------------|:---------------------|:---------------------|:--------------------|:-------|:--------------|
|3 |LdBPK_020440.1 |cytoplasmic: 0.54 |nuclear: 0.45 |mitochondrial: 0.0 |Golgi apparatus: 0.0 |peroxisomal: 0.0 |plasma membrane: 0.0 |extracellular: 0.0 |ER: 0.0 |lysosomal: 0.0 |
|5 |LdBPK_201720.1 |cytoplasmic: 0.89 |nuclear: 0.06 |mitochondrial: 0.02 |peroxisomal: 0.01 |Golgi apparatus: 0.01 |extracellular: 0.0 |plasma membrane: 0.0 |ER: 0.0 |lysosomal: 0.0 |
|6 |LdBPK_070130.1 |cytoplasmic: 0.61 |nuclear: 0.32 |peroxisomal: 0.05 |mitochondrial: 0.02 |Golgi apparatus: 0.0 |plasma membrane: 0.0 |extracellular: 0.0 |ER: 0.0 |lysosomal: 0.0 |
|7 |LdBPK_040060.1 |cytoplasmic: 0.52 |nuclear: 0.43 |mitochondrial: 0.02 |extracellular: 0.01 |peroxisomal: 0.01 |Golgi apparatus: 0.01 |plasma membrane: 0.0 |ER: 0.0 |lysosomal: 0.0 |
|13 |LdBPK_191560.1 |cytoplasmic: 0.49 |nuclear: 0.46 |mitochondrial: 0.03 |peroxisomal: 0.01 |Golgi apparatus: 0.0 |plasma membrane: 0.0 |extracellular: 0.0 |ER: 0.0 |lysosomal: 0.0 |
|15 |LdBPK_364730.1 |cytoplasmic: 0.93 |nuclear: 0.06 |mitochondrial: 0.0 |peroxisomal: 0.0 |Golgi apparatus: 0.0 |extracellular: 0.0 |plasma membrane: 0.0 |ER: 0.0 |lysosomal: 0.0 |
,在R控制台上看起来好一点,但这里虽然不是真的可读。
由于