我正在尝试保存逻辑测试循环中的数据。
所以我有以下数据:
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
我已经运行了以下循环
for (i in 1:49) {
print(T1 > F[i]) # I used print to see the results in the screen
}
这个循环返回 49 个填充有逻辑值(真或假)的矩阵。每个矩阵都是 T1 与 49 个位置 F[i] (F[1], ...., F[49]) 中每个位置的比较
我需要这些矩阵中的值,以便进一步用作网络图的邻接矩阵。但是,当我既不能将这些逻辑值分配给矩阵时,也不能使用“write.matrix”将它们保存在 csv 值中。
所以,我需要有 49 - 矩阵“W”填充逻辑值(T 或 F)。我已经通过上面的循环获得了这些值,但无法将其作为对象或 csv 集合获取。文件。
I tried
W<-matrix(0,26,26) #create an empty matrix to assign the logical arguments
for (i in 1:49){
W[i] <- T1>F[i] # I used print to see the results in the screen
}
返回以下警告
Warning messages:
1: In W[i] <- (T1 > F[i]) :
number of items to replace is not a multiple of replacement length
我还尝试了一种不同的设置,其中我比较的所有矩阵都具有相同的维度。
create.M <- function(F){ # a function to transform each position F[i] into a 26X26 matrix
for (i in 1:49) {
matrix(F[i],26,26)
}
}
Loop.T1 <- function(T1){ # a function to replicate T1(49 times)
for ( i in 1:49) {
T1
}
}
并比较两个输出
Loop.T1(T1)>create.M(F)
返回
logical(0)