我有一个for循环,它是这样的:
for (i=1:150000) {
tempMatrix = {}
tempMatrix = functionThatDoesSomething() #calling a function
finalMatrix = cbind(finalMatrix, tempMatrix)
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何让它平行吗?
我在网上尝试了这个例子,但我不确定语法是否正确.它也没有太多提高速度.
finalMatrix = foreach(i=1:150000, .combine=cbind) %dopar% {
tempMatrix = {}
tempMatrix = functionThatDoesSomething() #calling a function
cbind(finalMatrix, tempMatrix)
}
Run Code Online (Sandbox Code Playgroud) 我想增加ggtitle的字体大小,字体也应该是粗体.我的代码如下.
ggplot(df, aes(x1, y = value, colour = variable)) +
geom_point(size=2) +
ggtitle("male vs.female") +
theme(axis.text=element_text(size=14),
axis.title=element_text(size=14,face="bold")) +
theme(legend.text=element_text(size=12)) +
labs(x = "x axis", y = "y axis") +
ylim(0,100) + xlim(0,100) +
scale_colour_manual(values = c("red", "blue"),
labels = c("male", "female"))
Run Code Online (Sandbox Code Playgroud) 仅仅为了完成我的C++/Rcpp编程,我开始实现(样本)标准偏差函数:
#include <Rcpp.h>
#include <vector>
#include <cmath>
#include <numeric>
// [[Rcpp::export]]
double cppSD(Rcpp::NumericVector rinVec)
{
std::vector<double> inVec(rinVec.begin(),rinVec.end());
int n = inVec.size();
double sum = std::accumulate(inVec.begin(), inVec.end(), 0.0);
double mean = sum / inVec.size();
for(std::vector<double>::iterator iter = inVec.begin();
iter != inVec.end(); ++iter){
double temp;
temp= (*iter - mean)*(*iter - mean);
*iter = temp;
}
double sd = std::accumulate(inVec.begin(), inVec.end(), 0.0);
return std::sqrt( sd / (n-1) );
}
Run Code Online (Sandbox Code Playgroud)
我还决定测试stddevArmadillo库中的函数,考虑到它可以在向量上调用:
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
// [[Rcpp::export]]
double armaSD(arma::colvec …Run Code Online (Sandbox Code Playgroud) setwd("/mnt/mountpoint/abc/")
sqlServerConnString <- "SERVER=server;DATABASE=sqldwdb;UID=xyz;PWD=abc;"
sqlServerDataDS <- RxSqlServerData(sqlQuery = "SELECT * FROM xyz",
connectionString = sqlServerConnString)
sqlServerDataDF <- rxImport(sqlServerDataDS)
Run Code Online (Sandbox Code Playgroud)
这是我的代码.我在R中得到了跟随错误
[unixODBC] [驱动程序管理器]无法打开lib'SQL Server':找不到文件
[unixODBC] [驱动程序管理器]连接不存在SQLDisconnect中的ODBC错误无法打开doTryCatch中的数据源.错误(return(expr),name,parentenv,handler):无法打开数据源.
我在我的linux机器上安装了MSSQL和unixODBC驱动程序,它也在/etc/odbc.ini文件中被重新选中
有人可以帮我吗?
我想废弃一个https网站,但我失败了.
这是我的代码:
require(rvest)
url <- "https://www.sunnyplayer.com/de/"
content <- read_html(url)
Run Code Online (Sandbox Code Playgroud)
但我在控制台中出错 - "open.connection(x,"rb")出错:达到超时"我如何解决这个问题?
我试图运行python作为rmarkdwon代码块.我是sucessfull但默认使用rmarkdown使用python2并且我希望它使用python 3.我在安装了python 2.7.6的Ubuntu上运行它并且我安装了带有pytthon 3.5的anaconda,这是我想要rmarkdown使用的.这是rmarkdown中python块的代码和输出
```{python}
import sys
print (sys.version)
```
Run Code Online (Sandbox Code Playgroud)
和输出:
2.7.6 (default, Jun 22 2015, 17:58:13)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我只想找到带有重复单词HALL的行(不止一次).例如,"HALL #1 HALL #2 HALL #3".我试着用
grepl("HALL{2,}", "HALL #1 HALL #2 HALL #3")
Run Code Online (Sandbox Code Playgroud)
但grepl回来了FALSE.我究竟做错了什么?
在我的工作中,我安装了R-Studio(Microsoft R Open 3.2.5),并希望连接到Microsoft SQL Server数据库,使用我拥有的表运行脚本.
我是否有可能使用Pentaho连接到SQL Server数据库,然后使用对象执行R脚本来创建OLAP多维数据集?我需要一个包来连接SQL引擎吗?执行的步骤是什么?
我已经有了数据库的雪花arquitectura.使用事实表和状态表.但我不知道从哪里开始.
我正在阅读有关统计学习/机器学习和 R 的这本书。问题之一是:
首先,加载波士顿数据集。波士顿数据集是 R 中 MASS 库的一部分。
library (MASS)
Run Code Online (Sandbox Code Playgroud)
现在数据集包含在对象中
Boston。阅读有关数据集的信息:
?Boston
我不明白语法library(MASS)。我如何从中获得波士顿数据集?我试过了,Boston=library(MASS)但这给了我一系列的词:
"MASS" "stats" "graphics" "grDevices" "utils" "datasets" "methods" "base"
Run Code Online (Sandbox Code Playgroud)
我也尝试过类似的东西,Boston=library(MASS::Boston)但这似乎也无效。
我想使用一个将错误导出到.txt文件的函数.到目前为止,我有:
error.function <- function() {
cat(geterrmessage(), file="c:/bla.txt", append=TRUE)
}
Run Code Online (Sandbox Code Playgroud)
然后,
options("error"=error.function)
Run Code Online (Sandbox Code Playgroud)
但是,这只能给我error没有相应的行号我可以请求帮助以扩展error.function以及有关行号的信息(我在Rstudio中的脚本以line1开头并上升到第2500行?
r ×10
sql-server ×2
armadillo ×1
c++ ×1
ggplot2 ×1
grep ×1
microsoft-r ×1
pentaho ×1
performance ×1
python-3.5 ×1
r-markdown ×1
rcpp ×1
rvest ×1
web-scraping ×1