I have code for a loop that seems to mostly work, but when I try to output the results into a csv file, I get the following error, Error in file(file, ifelse(append, "a", "w")) : invalid 'open' argument.
I've written code for a loop (which has worked before) that takes a dataset from a folder, performs calculations and puts those calculations in new columns, and then outputs that dataset with the new columns into a different folder. However, R encounters a problem when trying to put the output into the new folder at the end of the loop, giving me the following error, Error in file(file, ifelse(append, "a", "w")) : invalid 'open' argument.
setwd("/Users/Desktop/Snail/CSVs/CSV 2")
files = list.files()
summary = NULL
for (f in files) {
data = read.csv(f, sep = ',',header=T)
data2<-prepData(data,type="UTM",coordNames=c("x","y"))
sub = cbind(f,data2)
summary = rbind(summary,sub)
myfile = file.path("/Users/Desktop/CSV 3",".csv")
write.table(summary[[f]], file=myfile , paste(names(summary)[f],".csv",sep=","))
}
I am hoping to get a file with the new calculations in the new folder.