在R中使用2d矩阵,如何创建3d曲面图,其中columns = x,rows = y,值是z中的高度?
在下面的示例中,x值为1:5,y值为1:5,数字表示z中的高度/值.
> m<-matrix(rnorm(25),nrow=5,ncol=5)
> m
[,1] [,2] [,3] [,4] [,5]
[1,] -1.495513045 0.8000040 -1.1499261 1.65661138 0.8140510
[2,] -1.150018195 -0.7582933 0.8306922 0.16026908 0.3913198
[3,] -0.852609406 0.5525621 0.3585986 -0.45054768 -1.2259927
[4,] -0.001926297 -0.5857351 2.1518281 0.03192463 0.2065039
[5,] -1.641128610 0.4333973 -1.0616628 -0.92143426 -0.9598991
Run Code Online (Sandbox Code Playgroud) 在R中,从范围中提取整数的有效方法是什么?
假设我有一个范围矩阵(column1 = start,column2 = end)
1 5
3 6
10 13
Run Code Online (Sandbox Code Playgroud)
我想将矩阵中所有范围的包含唯一整数存储到一个对象中:
1
2
3
4
5
6
10
11
12
13
Run Code Online (Sandbox Code Playgroud)
这将适用于包含约4百万个范围的矩阵,因此希望有人可以提供有效的解决方案.
我有一个长度为5,000,000的数字向量
>head(coordvec)
[1] 47286545 47286546 47286547 47286548 47286549 472865
Run Code Online (Sandbox Code Playgroud)
和一个3 x 1,400,000数字矩阵
>head(subscores)
V1 V2 V3
1 47286730 47286725 0.830
2 47286740 47286791 0.065
3 47286750 47286806 -0.165
4 47288371 47288427 0.760
5 47288841 47288890 0.285
6 47288896 47288945 0.225
Run Code Online (Sandbox Code Playgroud)
我想要完成的是,对于coordvec中的每个数字,找到子行中行的V3的平均值,其中V1和V2包含coordvec中的数字.为此,我采取以下方法:
results<-numeric(length(coordvec))
for(i in 1:length(coordvec)){
select_rows <- subscores[, 1] < coordvec[i] & subscores[, 2] > coordvec[i]
scores_subset <- subscores[select_rows, 3]
results[m]<-mean(scores_subset)
}
Run Code Online (Sandbox Code Playgroud)
这很慢,需要几天才能完成.有更快的方法吗?
谢谢,
担
我在局域网上有两台服务器,全新安装了Centos 6.4 minimal和R 3.0.1.两台计算机都安装了doParallel,snow和snowfall软件包.
服务器可以很好地互相ssh.
当我尝试在任一方向上创建集群时,我会收到密码提示,但输入密码后,它会无限期挂起.
makePSOCKcluster("192.168.1.1",user="username")
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
编辑:
我也尝试在上面提到的计算机上调用makePSOCKcluster,其主机能够用作从属设备(来自其他计算机),但它仍然挂起.那么,是否可能存在防火墙问题?我也尝试使用带端口22的makePSOCKcluster:
> makePSOCKcluster("192.168.1.1",user="username",port=22)
Error in socketConnection("localhost", port = port, server = TRUE, blocking = TRUE, :
cannot open the connection
In addition: Warning message:
In socketConnection("localhost", port = port, server = TRUE, blocking = TRUE, :
port 22 cannot be opened
Run Code Online (Sandbox Code Playgroud)
这是我的iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state …Run Code Online (Sandbox Code Playgroud)