在R中将向量转换成表格

在R中,对于长向量,如果需要展示,直接打印不够美观,可以将其转换为表格,美观而且直白,可以使用ggtexttable这个函数,比如,我们现在有一个向量,有许多基因名称,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# x是"character",长度是388
> class(x)
[1] "character"
> x
[1] "Adora1" "Dock10" "Rcsd1" "Myo1b"
[5] "Hecw2" "Raph1" "Serpine2" "Fam129a"
[9] "Ncf2" "Pappa2" "Sox17" "Tram2"
[13] "Mpp4" "Ino80d" "Igfbp5" "Tmbim1"
[17] "Dnajb3" "Acmsd" "Mdm4" "Hlx"
[21] "Smyd2" "Cd34" "Zeb2" "Rbms1"
[25] "Grin1" "Grin1os" "Notch1" "Adamts13"
[29] "Baz2b" "Pla2r1" "Dpp4" "Itgav"
[33] "Tnks1bp1" "D430041D05Rik" "Meis2" "Cdan1"
[37] "Sema6d" "Zmynd8" "Lama5" "Il15ra"
[41] "Tmem210" "Egfl7" "Stkld1" "Pkn3"
[45] "Wdr38" "Slc38a11" "Nostrin" "Dcaf17"
[49] "Pdk1" "Wipf1" "Serping1" "Eif2ak4"
[53] "Serinc4" "Gpat2" "Slc4a11" "Rrbp1"
[57] "Sstr4" "Defb28" "Defb29" "Defb21"
[61] "Defb19" "Cox4i2" "Ccm2l" "R3hdml"
[65] "Zfp972" "Helz2" "Sox18" "Tcea2"
[69] "Emcn" "Maml3" "Frem2" "Bcl9"
[73] "Igsf3" "Abca4" "Mgarp" "Fhdc1"
[77] "Efna1" "S100a6" "Rptn" "BC028528"
[81] "Mab21l3" "Prpf38b" "Alpk1" "Pitx2"
[85] "Cfi" "Tet2" "Nexn" "Srsf11"
[89] "Tie1" "Zfp292" "Zfp462" "Mroh7"
[93] "Hspg2" "Pnisr" "Fam166b" "Orm2"
[97] "Akna" "Psip1" "Angptl3" "Gja4"
[101] "Col16a1" "Ptpru" "Masp2" "Uts2"
[105] "Tnfrsf18" "Agrn" "Plekhn1" "Prom1"
[109] "Nos3" "Stk32b" "Cmklr1" "Flt1"
[113] "Steap4" "Kdr" "Rasa4" "Dysf"
[117] "Alms1" "Fgd5" "Adamts9" "Impdh1"
[121] "Hilpda" "Olfr434" "Gimap8" "Capg"
[125] "Tmsb10" "Plxnd1" "Fxyd4" "C1s1"
[129] "Vamp1" "Cd27" "Clec1b" "Clec9a"
[133] "Emp1" "Taok2" "Gltscr1" "Pafah1b3"
[137] "Gpi1" "Tjp1" "Arhgef17" "Pde2a"
[141] "Folr2" "Trim34b" "Chst15" "Myadm"
[145] "Pira1" "Gm14548" "Lilra6" "Leng8"
[149] "Cox6b2" "Tmem190" "Cyp2s1" "Cyp2t4"
[153] "Plekhg2" "Gapdhs" "Sbsn" "Fxyd5"
[157] "Snrnp70" "Gys1" "Rasip1" "Ldha"
[161] "Fes" "Trim6" "Trim34a" "Trim5"
[165] "Nlrp10" "Atxn2l" "Apobr" "Gdpd3"
[169] "Aldoa" "Tgfb1i1" "Bnip3" "Ano9"
[173] "Muc6" "Rasa3" "Dlc1" "Inpp4b"
[177] "Arhgef7" "Kifc3" "Nfat5" "Ankrd11"
[181] "Sipa1l2" "Tex29" "Plpp5" "Ankrd37"
[185] "Lrp2bp" "Ushbp1" "Plvap" "Sall1"
[189] "Fhod1" "Ctrl" "Fli1" "Phldb1"
[193] "Kmt2a" "Pstpip1" "Peak1" "Cspg4"
[197] "Parp6" "Coro2b" "Megf11" "Rasl12"
[201] "Rbm6" "Map4" "Ddi1" "Mmp7"
[205] "Mtnr1b" "AB124611" "Dock6" "Angptl8"
[209] "Robo4" "Esam" "Apoc3" "Trcg1"
[213] "Pkm" "Uchl4" "Plod2" "Sema3f"
[217] "Fam212a" "Ccr1" "Gpc3" "Atrx"
[221] "Plp2" "Ssxb5" "Gm6592" "Flna"
[225] "Dnase1l1" "Ogt" "Rgag4" "Arl13a"
[229] "Bhlhb9" "Arxes2" "Tspyl2" "Asb11"
[233] "Syne1" "Col13a1" "Mthfd1l" "Epb41l2"
[237] "Pfkl" "Fgd6" "Lrriq1" "Nxph4"
[241] "Hey2" "Prdm1" "Lilrb4a" "Rufy2"
[245] "Aire" "Ankrd24" "B4galnt1" "Arhgef25"
[249] "Mbd6" "Ndufa4l2" "Esyt1" "Npm1"
[253] "Slc22a4" "Arhgef15" "Efcab5" "Ppm1e"
[257] "Pitpnc1" "Itgb4" "Stc2" "Fndc9"
[261] "Olfr1396" "Btnl9" "Slc22a21" "Chrnb1"
[265] "Fgf11" "Nlgn2" "Tnk1" "Acap1"
[269] "Zmynd15" "Aldoc" "Wsb1" "Heatr9"
[273] "Higd1b" "Prr29" "Cep95" "Slc16a3"
[277] "Hif1a" "Ccdc88c" "Pqlc3" "Egln3"
[281] "Pnn" "Tomm20l" "Akap5" "Arg2"
[285] "Gm4787" "Jag2" "Crip1" "Nid1"
[289] "Zfp458" "Slc6a18" "Map3k1" "Parp8"
[293] "Pfkp" "Prl2c3" "Slc17a4" "Irf4"
[297] "Ppp1r3g" "Wnk2" "Fam193b" "Plk2"
[301] "Slc25a30" "Scel" "Il17rb" "Stab1"
[305] "Mmrn2" "Gm10375" "Ang" "Rnase4"
[309] "Arhgef40" "Tmem253" "Nfatc4" "Sox7"
[313] "Cysltr2" "Ednrb" "Ipo5" "Card6"
[317] "Fyb" "Parvb" "Shank3" "Fmnl3"
[321] "Slc11a2" "Map3k12" "Pabpc1" "Ptp4a3"
[325] "Gpihbp1" "Nrbp2" "Plec" "Mb"
[329] "Myh9" "Lgals2" "Cyp2d22" "Cyp2d11"
[333] "Mapk12" "Hdac7" "Kmt2d" "Ciita"
[337] "Erg" "Zc3h7a" "Atp13a4" "Heg1"
[341] "Arhgap31" "Cyyr1" "Setd4" "Dopey2"
[345] "AU021092" "Ypel1" "Apod" "Stx19"
[349] "Itgb2l" "Rasgrp3" "Spaca6" "Mapk8ip3"
[353] "Kank3" "Smchd1" "Srrm2" "Rab26"
[357] "Meiob" "Ccdc78" "Rgs11" "Notch3"
[361] "Pram1" "Notch4" "Msh5" "Mdc1"
[365] "Olfr99" "Olfr110" "Tnfsf9" "Gpr108"
[369] "Prelid2" "Nrg2" "Gm5820" "Pdgfrb"
[373] "Piezo2" "Slc14a1" "Setbp1" "Pcdhb15"
[377] "Arap3" "Lrp5" "Ahnak" "Tcirg1"
[381] "Lrfn4" "Cd248" "Fosl1" "Sipa1"
[385] "Rasgrp2" "Slc22a29" "Ppp1r3c" "Obfc1"
# 转换之前需要将其转化为向量,但向量需要定义行与列,需要满足整除,即长度=行数X列数,388=4X97,4行97列或者97行列都不匀称,因此,先改变它的长度至390(390=13X30),这样,可以做成13列30行的向量,大约1:3比率的矩形
> y <- c(x,"","")
> z <- matrix(y,ncol=13)
# 下面,转换为表格
> library(ggpubr)
> ggtexttable(z,rows = NULL,cols=NULL,theme = ttheme("classic"))
# 直接展示是很长而且杂乱的,表格则更加美观整洁。

  • 本文作者:括囊无誉
  • 本文链接: R/text_to_table/
  • 版权声明: 本博客所有文章均为原创作品,转载请注明出处!
------ 本文结束 ------
坚持原创文章分享,您的支持将鼓励我继续创作!