In this code I have tried to use a for loop for id values and some if if else statements because the files were in "001.csv", form and "010" form so I made this code. The plan was to store a character vector and then read it using read.csv
.
I used getwd()
function to get the working directory and then setwd
to set it as the same directory but it still didn't work. So basically breaking the loop in 1's and 10s I tried to form this function, the main issue is with reading this file.
Error in file(file, "rt") : cannot open the connection
is what it is showing to me. I use Windows 10 and Rstudio.
pollutmean <- function(pollutant="sulfate", id=1:332) {
for (i in id) {
if (i < 10) {
x <- i
char <- as.character(x)
a <- paste("C:/Users/ksart/Desktop/Specdata/Specdata/00", char, ".csv",
sep="") # this is where i m trying to read in the values
temp1 <- read.csv(a)
data_1 <- rbind.data.frame(data_1, temp1)
data_1
}
else if (10 <= i && i < 100 ) { # for 10s files
y <- i
char1 <- as.character(y)
b <- paste("C:/Users/ksart/Desktop/Specdata/Specdata/0", char1, ".csv",
sep="")