我通过描述文件使用 RDCOMClient 获得了 R 包:
建议:RDCOMClient
以及以下(完美运行)代码:
GetNewWrd <- function() {
stopifnot(require(RDCOMClient))
# Starts the Word application with wrd as handle
wrd <- RDCOMClient::COMCreate("Word.Application", existing=FALSE)
newdoc <- wrd[["Documents"]]$Add("",FALSE, 0)
wrd[["Visible"]] <- TRUE
invisible(wrd)
}
Run Code Online (Sandbox Code Playgroud)
如今,这似乎被认为是不好的做法,“编写 R 扩展,1.1.3.1 建议的包”告诉我们要制定:
if (requireNamespace("rgl", quietly = TRUE)) {
rgl::plot3d(...)
} else {
## do something else not involving rgl.
}
Run Code Online (Sandbox Code Playgroud)
或者: ..如果想要在建议的包不可用时给出错误,只需使用例如 rgl::plot3d。
重新编码(根据我的理解)意味着,只需删除要求语句:
GetNewWrd <- function() {
# Starts the Word application with wrd as handle
wrd <- RDCOMClient::COMCreate("Word.Application", existing=FALSE)
newdoc <- …Run Code Online (Sandbox Code Playgroud) format()在R中没有明显的选项来显示没有前导0的月份(和年份相同).有没有其他方法可以得到这个结果?该解决方案应允许用户灵活地选择是仅在当天或月份或年份或任何组合中省略0.
在: as.Date("2005-09-02")
出: 2/9/5
或0只删除一个月:
出: 2/9/05
我有一个数字向量v(已经省略了NA),并希望获得第n个最大值及其各自的频率.
我发现 http://gallery.rcpp.org/articles/top-elements-from-vectors-using-priority-queue/ 非常快.
// [[Rcpp::export]]
std::vector<int> top_i_pq(NumericVector v, unsigned int n)
{
typedef pair<double, int> Elt;
priority_queue< Elt, vector<Elt>, greater<Elt> > pq;
vector<int> result;
for (int i = 0; i != v.size(); ++i) {
if (pq.size() < n)
pq.push(Elt(v[i], i));
else {
Elt elt = Elt(v[i], i);
if (pq.top() < elt) {
pq.pop();
pq.push(elt);
}
}
}
result.reserve(pq.size());
while (!pq.empty()) {
result.push_back(pq.top().second + 1);
pq.pop();
}
return result ;
}
Run Code Online (Sandbox Code Playgroud)
但是,关系不会得到尊重.实际上我不需要索引,返回值也可以.
我想得到的是一个包含值和频率的列表,例如:
numv <- c(4.2, 4.2, 4.5, 0.1, 4.4, …Run Code Online (Sandbox Code Playgroud)