I'm working through a tutorial and am having a tough time on syntax. I cannot see where I'm going wrong but I'm getting error messages from the console.
I have a list of 300 csv files in a directory. A user would input the number (id) of the file they are seeking info on. The format is like so: 001.csv, 002.csv, 090.csv 250.csv etc etc.
The function is to convert the input into a string that is the csv file name. e.g. if id is 5, return 005.csv. If the input in 220, output 220.csv.
Here is the code:
csvfile <- function(id) {
if (id < 10) { paste0(0,0,id,".csv"
} else if (id < 100) {paste0(0,id,".csv"
}else paste0(id,".csv")
}
Here is the error that the console returns:
> csvfile <- function(id) {
+ if (id < 10) { paste0(0,0,id,".csv"
+ } else if (id < 100) {paste0(0,id,".csv"
Error: unexpected '}' in:
"if (id < 10) { paste0(0,0,id,".csv"
}"
> }else paste0(id,".csv")
Error: unexpected '}' in "}"
> }
I can see R is not liking some of my '}' but cannot figure out why? What's wrong with my syntax?