I am working in a directory, but the data I want to read is in a subdirectory. I get an error when I try to read the csv files, my code is the following:
setwd("~/Documents/")
files
f
for (i in 1:length(files)) {
f[[i]]
}
And the error I get is:
Error in file(file, "rt"): cannot open the connection
What am I doing wrong?
解决方案
The following will work, assuming you have correctly specified the other read.csv parameters.
setwd("~/Documents/")
files
f
for (i in 1:length(files)) {
f[[i]]
}
Alternatively, you could drop the paste0 and simply set your working directory to ~/Documents/data/ in the first place.
setwd("~/Documents/data/")
files
f
for (i in 1:length(files)) {
f[[i]]
}
If you need to be in ~/Documents/ at the end of this loop, then finish it up by adding the following after the loop.
setwd("~/Documents/")