我希望共享一个R函数,用于查找单个向量元素之间所有可能的唯一无向组合:
combi <- function(vec1)
{
si <- length(vec1)
first <- rep(vec1, (si-1):0)
secR <- rev(vec1)
second <- secR[sequence(1:(si-1))]
second <- rev(second)
combi <- matrix(cbind(first, second), ncol = 2)
return(combi)
}
Run Code Online (Sandbox Code Playgroud)
并询问是否有更简单的方法吗?(我需要将结果放在2列矩阵中).
主要思想是尝试创建一个具有标准Linux类型终端外观的应用程序.现在我只限于Java,这就是我想要的.
有没有足够简单的方法来做这样的事情.这应该是一个文本处理应用程序,应该独立于系统并独立运行.所有工作逻辑都应该来自用户输入.
有任何想法吗?
一段时间以来我一直在讨论这个问题......
我在js中有一个通常的构造函数/原型对象(如类),它包含我所有的d3图表逻辑:
figureGen = function(html_element) {
this.svg = d3.select(html_element)
.append('svg')
.style('width', '100%')
.style('height', '100%')
.append('g')
.attr("class", "sadrzalac")
.attr("transform", "translate(" + 0 + "," + 0 + ")");
this.element = element;
this.data = [];
this.yRange = d3.scale.linear();
this.xRange = d3.scale.linear();
this.xAxis = undefined;
this.yAxis = undefined;
this.width = undefined;
this.height = undefined;
this.zoom = undefined;
this.margin = {top: 20, right: 20, bottom: 20, left: 35};
this.svg.append("rect")
.attr("class", "clipPath")
.attr("transform", "translate(" + this.margin.left + "," + -this.margin.top + ")");
this.svg.append('g')
.attr("class","xaxis axis"); …
Run Code Online (Sandbox Code Playgroud) 我的目的是编写几个函数,旨在找到两个协方差矩阵之间的整体相似性,方法是将它们与随机向量相乘并关联响应向量,或者通过自举矩阵之一来获得可用于比较的相关系数分布。但在这两种情况下,我都得到了错误的结果。观察到的矩阵间相关性高达 0.93,但分布最多仅达到 0.2。这是函数的代码:
resamplerSimAlt <- function(mat1, mat2, numR, graph = FALSE)
{
statSim <- numeric(numR)
mat1vcv <- cov(mat1)
mat2vcvT <- cov(mat2)
ltM1 <- mat1vcv[col(mat1vcv) <= row(mat1vcv)]
ltM2T <- mat2vcvT[col(mat2vcvT) <= row(mat2vcvT)]
statObs <- cor(ltM1, ltM2T)
indice <- c(1:length(mat2))
resamplesIndices <- lapply(1:numR, function(i) sample(indice, replace = F))
for (i in 1:numR)
{
ss <- mat2[sample(resamplesIndices[[i]])]
ss <- matrix(ss, nrow = dim(mat2)[[1]], ncol = dim(mat2)[[2]])
mat2ss <- cov(ss)
ltM2ss <- mat2ss[col(mat2ss) <= row(mat2ss)]
statSim[i] <- cor(ltM1, ltM2ss)
}
if (graph == TRUE) …
Run Code Online (Sandbox Code Playgroud) 如果我想使用boot()
R's boot
软件包中的函数来计算两个向量之间的Pearson相关系数的重要性,我应该这样做:
boot(re1, cor, R = 1000)
Run Code Online (Sandbox Code Playgroud)
re1
这两个观测向量的两列矩阵在哪里?我似乎无法正确得到这个因为cor
这些向量0.8
,但上面的函数返回-0.2
为t0
.
这个问题是在堆栈溢出之前报告的,但不管我做什么,我仍然得到同样的东西.每当我尝试安装任何R包时,我都会得到以下信息:
install.packages("Hmisc", repos = "http://cran.r-project.org")
Installing package into ‘/home/budjajojo/R_packages’
(as ‘lib’ is unspecified)
trying URL 'http://cran.r-project.org/src/contrib/Hmisc_3.13-0.tar.gz'
Content type 'application/x-gzip' length 587751 bytes (573 Kb)
opened URL
==================================================
downloaded 573 Kb
* installing *source* package ‘Hmisc’ ...
** package ‘Hmisc’ successfully unpacked and MD5 sums checked
** libs
sh: make: command not found
ERROR: compilation failed for package ‘Hmisc’
* removing ‘/home/budjajojo/R_packages/Hmisc’
The downloaded source packages are in
‘/tmp/Rtmp6fA61h/downloaded_packages’
Warning message:
In install.packages("Hmisc", repos = "http://cran.r-project.org") :
installation of …
Run Code Online (Sandbox Code Playgroud) 我的问题可能是由于 CGAL c++ 库中的新手,但我的任务一直在溜走。即,我想找到一组点的 alpha 形状,但似乎我不了解可用于 2D alpha 形状的迭代器。
这是我尝试过的:
Alpha_shape_2 alpha(pointsVec.begin(), pointsVec.end(), FT(1000), Alpha_shape_2::GENERAL);
//which compiles nicely and provides the regular output where pointsVec is the list of Point_2
//Then I saw the edge iterator at the CGAL documentation
template <class OutputIterator> //Method-iterator for CGAL alpha shapes in order to get the edges from alpha shape object
void alpha_edges( const Alpha_shape_2& A,
OutputIterator out)
{
for(Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin();
it != A.alpha_shape_edges_end();
++it){
*out++ = A.segment(*it);
}
}
//Then …
Run Code Online (Sandbox Code Playgroud) 我很抱歉,这可能很容易成为一个天真的问题,但我想弄清楚节点是如何工作的,特别是对于这样的问题:
我需要做的是通过require和module.exports 从fs.readFile发送一个对象/文件.这就是我试过的
在一个文件(称为app.js)中读取文件的代码:
var fs = require('fs');
var file_contents = undefined;
var callback_reader = function(err, data) {
if (err) return console.error(err);
file_contents = data.toString().split('\n');
}
module.exports = {
parseFile: function(file_path) {
fs.readFile(file_path.toString(), 'utf-8', callback_reader);
}
}
Run Code Online (Sandbox Code Playgroud)
在一些其他文件中,(称之为main.js)我需要使用readFile读取的文件内容,如下所示
var file_importer = require('./app.js')
file_importer.parseFile(real_path_to_file);
Run Code Online (Sandbox Code Playgroud)
但如果我尝试最后一行的console.log,我总是得到未定义的对象.现在我知道这是因为回调没有在console.log之前执行,但我不确定如何实现这种通信.