I just started r about a week ago. In my directory, I have csv files named 001, 002,...010,...331. In my partial function below, the user is requested to enter id (e.g. 1:9). The id is then converted into 001, 002, 003,...009. However, if the user enters say 1:10 for the id, the function will output id [10] as "0010" instead of as "010". This causes the rest of my function to fail. Any suggestions on what might be going on? If I enter 1:10, I want to get 001, 002, 003, 004, 005, 006, 007, 008, 009 and 010.
pollutantmean <- function(directory, pollutant, id) {
if((id>=1) && (id<10)) {
fn <- paste("00",id,sep="")
print(fn)
} else if((id>=10) && (id<=99)) {
fn <- paste("0",id,sep="")
print(fn)
} else {
fn <- id
print(fn)
}
Please I don't want to use R apply function for this. I have not gotten that far.