【发布时间】:2019-11-28 22:15:57
【问题描述】:
我正在尝试遍历数据框并连接 Rcpp 中由空格分隔的单词块。
我尝试阅读有关 Stack Overflow 的一些答案,但我对如何在 Rcpp 中连接字符串感到非常困惑。 (例如Concatenate StringVector with Rcpp)
我知道在 C++ 中你可以只使用 + 运算符来添加字符串。
这是我下面的 Rcpp 函数
cppFunction('
Rcpp::StringVector formTextBlocks(DataFrame frame) {
#include <string>
using namespace Rcpp;
NumericVector frame_x = as<NumericVector>(frame["x"]);
LogicalVector space = as<LogicalVector>(frame["space"]);
Rcpp::StringVector text=as<StringVector>(frame["text"]);
if (text.size() == 0) {
return text;
}
int dfSize = text.size();
for(int i = 0; i < dfSize; ++i) {
if ( i !=dfSize ) {
if (space[i]==true) {
text[i]=text[i] + text[i+1] ;
}
}
}
return text;
}
')
错误在error: no match for 'operator+'的行
如何在循环中连接字符串?
【问题讨论】: