我在R中有一个带列名的矩阵
。
> colnames(m)
[1] "caz_RNAi1_R1" "caz_RNAi2_R1" "cg1316_RNAi1_R1" "cg1316_RNAi2_R1" "cg4612_RNAi1_R1"
[6] "cg4612_RNAi2_R1" "Dp1_RNAi1_R1" "Dp1_RNAi2_R1" "fmr1_RNAi1_R1" "fmr1_RNAi2_R1"
[11] "GFP_RNAi1_R1" "GFP_RNAi2_R1" "GFP_RNAi3_R1" "GFP_RNAi4_R1" "GFP_RNAi5_R1"
[16] "GFP_RNAi6_R1" "hrb87f_RNAi1_R1" "hrb87f_RNAi2_R1" "hrb98de_RNAi1_R1" "hrb98de_RNAi2_R1"
现在,一些列名有前缀
GFP
。我想重新排列矩阵的列,使得那些在名称中具有此前缀的列成为开始的列,其余的列在它们自己之间按字母顺序排序。因此,
colnames(m)
应该像这样排序:"GFP_a", "GFP_b", "GFP_c",..."GFP_z", "a", "b","c","d", ....
如何完成这个任务?