小编Phi*_*eno的帖子

R中的循环:如何保存输出?

我试图从逻辑测试循环中保存数据.

所以我有以下数据:

T1 <- matrix(seq(from=100000, to=6600000,length.out=676),26,26) # a matrix of 26X26 - here with illustrive values

minmax <- seq(from=1,to=49,by=1) # creates a sequence
Fstep <- 6569141.82/minmax       # define a vector from 0 to 6569141.82 with 49 divisions
F <- rev(round(Fstep,0))         # round the vector values and re order them
F
Run Code Online (Sandbox Code Playgroud)

我已经运行了以下循环

for (i in 1:49) {
  print(T1 > F[i]) # I used print to see the results in the screen
}
Run Code Online (Sandbox Code Playgroud)

这个循环返回49个用逻辑值(True或false)填充的矩阵.每个矩阵是T1与49个位置F [i](F [1],....,F [49])中的每一个的比较

我需要在这些矩阵中包含值,以便进一步用作网络图的邻接矩阵.但是,当我既不能将这些逻辑值分配给矩阵时,也不能使用"write.matrix"将它们保存在csv值中.

所以,我需要有49个矩阵"W"用逻辑值(T或F)填充.我已经通过上面的循环得到了这些值,但我无法将其作为对象或csv的集合.文件.

我试过了

W<-matrix(0,26,26) #create …
Run Code Online (Sandbox Code Playgroud)

for-loop r matrix logical-operators

7
推荐指数
2
解决办法
5万
查看次数

标签 统计

for-loop ×1

logical-operators ×1

matrix ×1

r ×1