我有以下标题列表:
cols = c("to_test.namespace.(1,Inf]","to_test.namespace.(1,20]","from_test.namespace.(1,200]")
我需要放下(
然后]
。
如果我应用这段代码,它仅适用于to_test.namespace.(1,Inf]
,其余的则不起作用。
out <- sub("\\.?\\((\\d+),\\s*([A-Za-z]+)\\]$", "_\\1_\\2", cols)
我需要得到以下结果:
cols = c("to_test.namespace.1_Inf","to_test.namespace.1_20","from_test.namespace.1_200")
要么:
cols = c("to_test.namespace_1_Inf","to_test.namespace_1_20","from_test.namespace_1_200")
两种选择都很好。
我该怎么办?
我们可以用
sub("\\.\\(([^,]+),([^[]+)\\]", "_\\1_\\2", cols)
#[1] "to_test.namespace_1_Inf" "to_test.namespace_1_20" "from_test.namespace_1_200"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句