I've just started with R, I'm a self-taught person and I have a problem with my loop. I was looking for answers but nowhere I can't find anything.
I've got a lot of files with different names and also I've got a lot datas in one file. I made a loop for one file and it works good - it's like this (but it has more calculations):
12bielawica9.txt looks like
NA NA NA 0.002 0.002 NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA 0.008 0.006 NA NA NA NA NA NA NA NA NA NA NA NA NA NA
but it's much more bigger
It contains results of researches, that's why there's a lot of NAs. Sometimes it looks different like reasearches....(there's less NAs) I also wrote in R
dane = dane = read.table("12bielawica9.txt", header=T)
for (i in dane) {
x = sd(i, na.rm=T)
y = length (na.omit(i))
if (y == 0) {
cat(file="12bielawica9.txt", append=T, (paste("-","\t")))
} else if (x == "0") {
cat(file="12bielawica9.txt", append=T, paste(format(mean(i, na.rm=T) - mean(i, na.rm=T), digits=5), "\t"))
} else {
cat(file="12bielawica9.txt", append=T, paste(format(t.test(na.omit(i), conf.level=0.90)$conf.int - mean(i, na.rm=T), digits=5), "\t"))
}
}
First of all I'd like to create a loop for all files, but when I made a loop like:
myfiles <- list.files(pattern=".*txt")
for (j in 1:length(myfiles)) {
for (i in myfiles[j]) {
#LOOP FROM ABOVE
}
}
And now, list.files returns every file (like a 12bielawica.txt), on which I need to make calculations. Is it clear?
R return just one result for every file (like a conjuction). I'd like to achieve as a result a matrixes for every file (like from the my first loop ). I also don't know how to write a new file automaticaly...
I hope You understand what I mean. Don't be strict for me, please.