【发布时间】:2020-05-02 08:47:57
【问题描述】:
我正在尝试在 R 中的循环中编写一个文件。我想在我们通过循环时附加该文件。我试过 append=true 但没有用。我已经详细解释了问题here。任何想法?感谢您的帮助:
#Initilaizing 2*2 array
Array1 <- array(0,c(2,2))
for(i in 1:5)
{
#Create 4 random numbers
Random1 <- runif(1, min=0, max=1)
Random2 <- runif(1, min=0, max=1)
Random3 <- runif(1, min=0, max=1)
Random4 <- runif(1, min=0, max=1)
#Assign Random numbers to the array
Array1[1,1] <- Random1
Array1[1,2] <- Random2
Array1[2,1] <- Random3
Array1[2,2] <- Random4
#*****This is the Question*******
# I want to keep the history for Array1 through the 5 loops by writing the array in a file.
# and appending the file as we go through the loop
# I tried write.csv with Append=true but didn't work
# How can I do this?
}
【问题讨论】:
-
我在你的代码中没有看到任何
write.csv。 -
我试过 write.csv(Array1, file= "OUT1.csv", append=true) 但没有成功。
-
@movassat 它应该是
append=TRUE。在 R 中,布尔对象可以取两个值TRUE或FALSE。 -
write.csv(Array1, file= "OUT4.csv", append=TRUE) 。我在循环中尝试了这个,仍然只写下最后一次迭代结果
-
向我们展示代码(全部)或工作示例。