While循环嵌套在for循环R中
我试图使用for和while循环提取R中的单个主题数据。我希望循环相应地提取数据并将其保存为自己的数据文件。问题是for循环没有正确计算主题数并返回b的正确值。我的while循环工作得很好,因为我可以手动设置b的值,运行循环,并生成正确的数据文件While循环嵌套在for循环R中,r,loops,for-loop,while-loop,nested-loops,R,Loops,For Loop,While Loop,Nested Loops,我试图使用for和while循环提取R中的单个主题数据。我希望循环相应地提取数据并将其保存为自己的数据文件。问题是for循环没有正确计算主题数并返回b的正确值。我的while循环工作得很好,因为我可以手动设置b的值,运行循环,并生成正确的数据文件 Subjects = (1:2) r = (1); ST = (d$onReadyTime) #need to get ST to read not just the first number in onReadyTime for each tria
Subjects = (1:2)
r = (1);
ST = (d$onReadyTime) #need to get ST to read not just the first number in onReadyTime for each trial
ST=strsplit(ST,split = "a")
for (b in (1:length(Subjects)){
b <- Subjects[r]
while (r == Subjects[b])
{STSubject = (ST[[b]])
ST2=(STSubject)
#ST2=`colnames<-`(ST2,Subjects[i])
write.table(ST2,file = paste("ST_Subject_",b,".csv",sep=""),row.names = FALSE, col.names= TRUE)
r = r+1
}
}
Subjects=(1:2)
r=(1);
ST=(d$onReadyTime)#需要让ST在每次试验中读取onReadyTime中的第一个数字
ST=strsplit(ST,split=“a”)
用于(b英寸(1:长度(主题)){
b没有最低限度的工作示例,只能提供一般指导
n <- 0
for (i in seq_along(models)) {
for (j in seq_along(meters)) {
n <- n + 1
make_line(i, j) -> glances[[n]]
}
}
nb
是循环变量,您可以在循环的第一条指令中更改它。这是如何工作的?我不知道!我已经习惯了MATLAB,所以还在这里学习。