再現可能な例が必要です。
は、おそらくあなたが何かを探している:私のテストに基づいて、ところで
#string AO-A12D.01TCGA --> A12D
row.names(x)<-gsub(".*-(.*)[.].*", "\\1", row.names(x)) #where x has values like "AO-A12D.01TCGA"
#string TCGA-A2-A0T2 --> TCGA-A2-A0T2
row.names(x)<-gsub(".*-.*-(.*)", "\\1", row.names(x)) #where x has values like "TCGA-A2-A0T2"
#row.names gets row names of data frame
#gsub defines a regular expression/pattern, where:
#gsub("pattern", "stuff to replace pattern with", data)
#in regular expression language:
#.* = anything
#[.] = a literal "dot"
#(string) = part of pattern you want to keep
#\\1 means keep only the stuff in parentheses
あなたが上でそれらを呼び出す場合は、これらの正規表現のどちらも間違った文字列型のサブセット化によって、誤ったエラーを生成します同じデータセット。
サンプルデータを 'dput()'してください。この例の背後にある論理についても説明してください。それはちょうど '-'と' .'の位置に基づいていますか? –
rownameの残りの部分と区別したい文字列を定義するものは何ですか?それは常に4文字ですか?与えられたrownameに4文字もの長さの他の部分文字列があるかもしれませんか? '-'と' .'は唯一の区切り文字ですか?最初のケースでは – rosscova
は - と - に基づいています。 2番目のケースでは、最後の4文字を取る必要があります –