I am reading multiple txt files and I would like to remove the first row and save it as a variable, transpose it and later when I'm done doing stuff I would like to save it along with other variables in a file.
The problem is that my code is just saving the first txt information and repeating it for the rest of the txt files.
My code:
for(i in 1:length(filesW))
{
data <- read.table(paste0("data",i,".txt", sep=""), sep=",", header=TRUE)
winstepsdat2 <- data.frame(data)
genparameter<-t((winstepsdat2[1,]))
winstepsdat<-winstepsdat2[-1,]
num_col<-ncol(winstepsdat)
num_row<-nrow(winstepsdat)
colnames(winstepsdat) <- paste("i", 1:num_col, sep="")
winstepsdat$name<- paste ("p", 1:num_row, sep="")
#must change ni and labels for 1:n??
cmd <- wcmd(title = "R2Winsteps Example", data=paste0("data",i,".txt"),item1 = 1, ni =num_col , name1 = 30, namelen = 20,labels = paste('i', 1:num_col, sep = ""), hlines = "Y" ) #codes=1:5
write.wdat(winstepsdat, cmd)
write.wcmd(cmd, paste0("CMFILE[",i,"].cmd"))
winsteps2(cmd, outfile=paste0("outfile[",i,"].txt"), pfile=paste0("pfile",i,".txt"), ifile=paste0("ifile",i,".txt"), windir="C:/Winsteps/Winsteps.exe")
} #end for
Somehow winstepsdat does change as I go through text files (given that I get different values for other calculations, but genparameter just keeps the first txt file values. How can I store/save genparameter for every text file I read?
I'm a beginner programmer so I would appreciate the help. Thanks, Shmy