连续将结果保存在 R 的同一个文件中

continuously save result in the same file from R

我需要对多个 countries.So 执行相同的分析,每次我得到结果时,我想将不同国家的结果(FPR;TPR)保存在 R 的同一个文件中,但它会覆盖结果。我怎样才能继续在同一个文件上导出结果而不必丢失以前的结果。 感谢您的帮助!

  Countries <- c("Brussel")
  FPR <- c(FPR.GL)
  TPR <- c(TPR.GL)
  glob <- data.frame(Countries, FPR, TPR)

  write.table(glob, file="result_glob.txt")
  glob <- read.table("result_glob.txt")

只需使用 append 参数。来自 ?write.table

append: logical. Only relevant if 'file' is a character string. If 'TRUE', the output is appended to the file. If 'FALSE', any existing file of the name is destroyed.

所以第一次写入文件时,使用

write.table(glob, file="result_glob.txt) 

然后后续写入,使用

write.table(glob, file="result_glob.txt, col.names = FALSE)

避免添加列名。