输入向量将是
in <- c("Aone1","BZtwo2","AZtwenty4Btwo5","Cthirty22HIfour9")
我需要最终输出为
out <- c("one","two","twenty","two","thirty","four")
提取基于大写字母和数字之间的小写字母。
答案 0 :(得分:0)
您是否只想提取字符串的小写部分?如果是这样,请尝试:
v1 <- c("Aone1", "BZtwo2", "AZtwenty4Btwo5", "Cthirty22HIfour9")
regmatches(v1, gregexpr("[a-z]+", v1))
# [[1]]
# [1] "one"
#
# [[2]]
# [1] "two"
#
# [[3]]
# [1] "twenty" "two"
#
# [[4]]
# [1] "thirty" "four"
如果您想获得单个字符向量而不是unlist()
,请在list
中包含上述内容。