按顺序计算字符,忽略给定字符(R)

时间:2018-04-25 10:18:56

标签: r string vector count

我有一个单字符串向量:

seq <- c("c","t","c","t","c","c","t","a","t", "g", "g", "c", "g", "g", "g", "a", "a", "g", "c", "-", "-", "a", "a","-", "-", "-", "c", "t", "g")

我想创建一个等长的向量,从起始整数计算字符串,但忽略&#34; - &#34;。

例如,如果起始整数是1000

输出字符串为:

out <-c(1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, NA, NA, 1019, 1020, NA, NA, NA, 1021, 1022, 1023)

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:5)

这很简单:

function caps_caps($var) {
    $var = strrev(ucwords(strrev($var)));
    echo $var;
}

caps_caps("HeLlo WOrld"); // should returns "hellO worlD"