私はこのオブジェクトを持っています:
nr.genes<-structure(c("0", "Pipas_chr3_1145", "Pipas_chr3_1145", "Pipas_chr1-4_0581",
"Pipas_chr1-4_0582", "Pipas_chr1-4_0584", "Pipas_chr2-1_0006",
"Pipas_chr2-2_0010", "Pipas_chr3_0002", "0", "0", "Pipas_c034_0013",
"Pipas_chr1-4_0582", "Pipas_chr3_0002", "Pipas_chr4_0878", "Pipas_chr4_1001",
"Pipas_chr4_0878", "Pipas_chr4_1001", "0", "Pipas_chr1-4_0581",
"Pipas_chr1-4_0582", "Pipas_chr2-2_0010", "Pipas_chr3_0002",
"Pipas_chr4_0878", "Pipas_chr4_1001", "0", "Pipas_c131_0003",
"Pipas_chr1-1_0281", "Pipas_chr1-3_0004", "Pipas_chr3_1145",
"Pipas_chr4_0003", "Pipas_c034_0013", "Pipas_c131_0003", "Pipas_chr1-3_0004",
"Pipas_chr3_1145", "Pipas_chr4_0003", "0"), .Names = c("Nr11",
"Nr12", "Nr13", "Nr141", "Nr142", "Nr143", "Nr144", "Nr145",
"Nr146", "Nr21", "Nr22", "Nr23", "Nr241", "Nr242", "Nr311", "Nr312",
"Nr321", "Nr322", "Nr33", "Nr341", "Nr342", "Nr343", "Nr344",
"Nr345", "Nr346", "Nr41", "Nr421", "Nr422", "Nr423", "Nr424",
"Nr425", "Nr431", "Nr432", "Nr433", "Nr434", "Nr435", "Nr44"))
そして、私はこの名前で名前を変更したいと思います:
nr.genes.names<-c("up.p33-dw.p33", "up.p33-dw.p38", "up.p33-dw.p52", "up.p33-dw.p64",
"up.p38-dw.p33", "up.p38-dw.p38", "up.p38-dw.p52", "up.p38-dw.p64",
"up.p52-dw.p33", "up.p52-dw.p38", "up.p52-dw.p52", "up.p52-dw.p64",
"up.p64-dw.p33", "up.p64-dw.p38", "up.p64-dw.p52", "up.p64-dw.p64"
)
したがって、の最終結果nr.genes
は
structure(c("0", "Pipas_chr3_1145", "Pipas_chr3_1145", "Pipas_chr1-4_0581",
"Pipas_chr1-4_0582", "Pipas_chr1-4_0584", "Pipas_chr2-1_0006",
"Pipas_chr2-2_0010", "Pipas_chr3_0002", "0", "0", "Pipas_c034_0013",
"Pipas_chr1-4_0582", "Pipas_chr3_0002", "Pipas_chr4_0878", "Pipas_chr4_1001",
"Pipas_chr4_0878", "Pipas_chr4_1001", "0", "Pipas_chr1-4_0581",
"Pipas_chr1-4_0582", "Pipas_chr2-2_0010", "Pipas_chr3_0002",
"Pipas_chr4_0878", "Pipas_chr4_1001", "0", "Pipas_c131_0003",
"Pipas_chr1-1_0281", "Pipas_chr1-3_0004", "Pipas_chr3_1145",
"Pipas_chr4_0003", "Pipas_c034_0013", "Pipas_c131_0003", "Pipas_chr1-3_0004",
"Pipas_chr3_1145", "Pipas_chr4_0003", "0"), .Names = c("up.p33-dw.p33",
"up.p33-dw.p38", "up.p33-dw.p52", "up.p33-dw.p64", "up.p33-dw.p64",
"up.p33-dw.p64", "up.p33-dw.p64", "up.p33-dw.p64", "up.p33-dw.p64",
"up.p38-dw.p33", "up.p38-dw.p38", "up.p38-dw.p52", "up.p38-dw.p64",
"up.p38-dw.p64", "up.p52-dw.p33", "up.p52-dw.p33", "up.p52-dw.p38",
"up.p52-dw.p38", "up.p52-dw.p52", "up.p52-dw.p64", "up.p52-dw.p64",
"up.p52-dw.p64", "up.p52-dw.p64", "up.p52-dw.p64", "up.p52-dw.p64",
"up.p64-dw.p33", "up.p64-dw.p38", "up.p64-dw.p38", "up.p64-dw.p38",
"up.p64-dw.p38", "up.p64-dw.p38", "up.p64-dw.p52", "up.p64-dw.p52",
"up.p64-dw.p52", "up.p64-dw.p52", "up.p64-dw.p52", "up.p64-dw.p64"
))
しかし、これらの式を試してみると、うまくいきません。
attr(nr.genes, "names") <- nr.genes.names[as.integer(gsub('^Nr[0-9]([0-9]).*','\\1',attr(nr.genes, "names")))]
問題はパターンまたは置換にあると思います。最初の 4 つの名前を代わりに取得し、その後それらが繰り返されるためです。私はchartr()
それが役立つとは思わないまで見てきました。どうすれば改善できgsub
ますか?
編集:から変更したい
Nr11 by up.p33-dw.p33
Nr12 by up.p33-dw.p38
Nr13 by up.p33-dw.p52
Nr14 by up.p33-dw.p64
Nr21 by up.p38-dw.p33
Nr22 by up.p38-dw.p38
Nr23 by up.p38-dw.p52
Nr24 by up.p38-dw.p64
Nr31 by up.p52-dw.p33
Nr32 by up.p52-dw.p38
Nr33 by up.p52-dw.p52
Nr34 by up.p52-dw.p64
Nr41 by up.p64-dw.p33
Nr42 by up.p64-dw.p38
Nr43 by up.p64-dw.p52
Nr44 by up.p64-dw.p64