本文整理汇总了C++中CharacterVector::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ CharacterVector::erase方法的具体用法?C++ CharacterVector::erase怎么用?C++ CharacterVector::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CharacterVector
的用法示例。
在下文中一共展示了CharacterVector::erase方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: path_to_filename
CharacterVector path_to_filename(CharacterVector filenames){
Environment base("package:base");
Function strsplit = base["strsplit"];
Function paste = base["paste"];
List split_res(filenames.size());
CharacterVector lasts(filenames.size());
NumericVector lengths(filenames.size());
for(int i = 0; i < filenames.size(); ++i){
CharacterVector res = as<CharacterVector>(as<List>(strsplit(as<std::string>(filenames[i]), "/"))[0]);
for(int r = 0; r < res.size(); ++r) //Remove empty substrings
if(res[r] == "") res.erase(res.begin() + r, res.begin() + r + 1);
split_res[i] = res;
lengths[i] = res.size();
lasts[i] = res[lengths[i] - 1];
}
// Check if there are any duplicates in last
if(unique(lasts).size() == lasts.size())
return(lasts);
int longest_possible_sub = (int) min(lengths) - 1;
bool all_equal = true;
for(int i = 0; i < longest_possible_sub; ++i){
for(int f = 1; f < filenames.size(); ++f){
if(as<CharacterVector>(split_res[0])[0] != as<CharacterVector>(split_res[f])[0]){
all_equal = false;
break;
}
}
// if they\'re all the same trim them
if(all_equal){
for(int f = 0; f < filenames.size(); ++f){
CharacterVector res = split_res[f];
CharacterVector::iterator it = res.begin();
res.erase(it, it + 1);
split_res[f] = res;
}
}
}
CharacterVector results(filenames.size());
for(int f = 0; f < filenames.size(); ++f){
results[f] = as<CharacterVector>(paste(split_res[f], Named("collapse", "_")))[0];
}
return(results);
}
示例2: group_vars
SymbolVector GroupedDataFrame::group_vars(SEXP x) {
check_grouped(x);
static SEXP groups_symbol = Rf_install("groups");
SEXP groups = Rf_getAttrib(x, groups_symbol);
int n = Rf_length(groups) - 1;
CharacterVector vars = Rf_getAttrib(groups, R_NamesSymbol);
vars.erase(n);
return SymbolVector(vars);
}