我在x中搜索4个不同子串的位置,并尝试将这四个输出合并为一个累积字符串:
x <- ("AAABBADSJALKACCWIEUADD")
outputA <- gregexpr(pattern = "AAA", x)
outputB <- gregexpr(pattern = "ABB", x)
outputC <- gregexpr(pattern = "ACC", x)
outputD <- gregexpr(pattern = "ADD", x)
我想合并这四个输出并将此合并结果作为文本文件输出,每个元素在新行上分开。
merged_output
# 1
# 3
# 13
# 20
谢谢
答案 0 :(得分:5)
实际上,您可以使用前瞻cv::sortIdx(temp, ind, CV_SORT_EVERY_COLUMN + CV_SORT_DESCENDING);
(?=)
答案 1 :(得分:2)
例如
library(stringi)
cat("merged_output",
paste("#",
stri_locate_first_fixed(pattern = c("AAA", "ABB", "ACC", "ADD"), ("AAABBADSJALKACCWIEUADD"))[, "start"]),
file = tf <- tempfile(fileext = ".txt"),
sep = "\n")
现在,tf
中指定的文件包含
> merged_output
> # 1
> # 3
> # 13
> # 20
答案 2 :(得分:1)
不是很自动化,但是
cat(paste(c(outputA[[1]][1], outputB[[1]][1], outputC[[1]][1], outputD[[1]][1]),
collapse = "\n"),
file = "outputfile.txt")
应该这样做。