我有以下行命名方案的數據集:可變長度核心名稱識別
a.X.V
where:
a is a fixed-length core ID
X is a variable-length string that subsets a, which means I should keep X
V is a variable-length ID which specifies the individual elements of a.X to be averaged
. is one of {-,_}
我所試圖做的是採取一切a.X's
列平均值。樣本:
sampleList <- list("a.12.1"=c(1,2,3,4,5), "b.1.23"=c(3,4,1,4,5), "a.12.21"=c(5,7,2,8,9), "b.1.555"=c(6,8,9,0,6))
sampleList
$a.12.1
[1] 1 2 3 4 5
$b.1.23
[1] 3 4 1 4 5
$a.12.21
[1] 5 7 2 8 9
$b.1.555
[1] 6 8 9 0 6
目前,我手動gsubbing出.Vs
得到的一般列表:
sampleList <- t(as.data.frame(sampleList))
y <- rowNames(sampleList)
y <- gsub("(\\w\\.\\d+)\\.d+", "\\1", y)
有一個更快的方法來做到這一點?
這是我在工作流程中遇到的兩個問題的一半。另一半回答了here。
你所說的 '手動gsubbing' 是什麼意思?你的意思是多次調用'gsub'? –