我需要创建一个以这种方式创建字符串序列的函数:
as.character(c(seq(0.1, 0.9, by = 0.1),
"0.10", seq(0.11, 0.19, by = 0.01),
"0.20", seq(0.21, 0.29, by = 0.01)))
[1] "0.1" "0.2" "0.3" "0.4" "0.5" "0.6" "0.7" "0.8" "0.9" "0.10" "0.11" "0.12" "0.13" "0.14"
[15] "0.15" "0.16" "0.17" "0.18" "0.19" "0.20" "0.21" "0.22" "0.23" "0.24" "0.25" "0.26" "0.27" "0.28"
[29] "0.29"
简而言之,我需要" 0.1"区别于" 0.10"在序列中,我需要能够指定一个范围,例如"0.8", "0.9", "0.10", "0.11"
或"0.3", "0.4", "0.5"
。
例如,my_seq("0.8", "0.11")
会返回"0.8", "0.9", "0.10", "0.11"
。
答案 0 :(得分:0)
这有用吗?
fn = function(){
as.character(c(seq(0.1, 0.9, by = 0.1),
"0.10", seq(0.11, 0.19, by = 0.01),
"0.20", seq(0.21, 0.29, by = 0.01)))
}
fn()