Hi Friends.
I have been wondering if it is possible to make a loop in file directory, I would like to change the txt file whenever code run is finished and then keep going to the next file...
For instance: I want to change FileGD automatically, when the code is finished. and run again for the next txt file.
Can you help me?
rm(list=ls())
library(stringr)
library(data.table)
FileGD = ("Matrix1.txt")
ColumnName<- data.frame(fread(file = FileGD, header = FALSE, sep = "\t"))[1,]
MatrixGD<- data.frame(fread(file = FileGD, header = TRUE, sep = "\t"))
Num.C<-ncol(MatrixGD)
colnames(MatrixGD)<- c(ColumnName)
GDFile<-cbind(MatrixGD[1], stack(lapply(MatrixGD[2:Num.C], as.character)))
colnames(GDFile)<- c("Hybrids", "GD", "Tester")
GDFile2<- str_c(GDFile$Hybrid, "/", GDFile$Tester)
GDFinal<- data.frame(GDFile2, GDFile[2])
colnames(GDFinal)<- c("Hybrids", "GD")
fwrite(GDFinal, "ArquivoGD.txt", row.names = FALSE, sep = "\t")