Why this works:
PC<-read.csv('./public-transportation/san-francisco/passenger-count.csv', header=TRUE)
But the following doesn't work in R:
inputFile <-paste('./public-transportation/',
'san-francisco/passenger-count.csv')
PC<-read.csv(inputFile, header=TRUE)
All I am doing is passing a variable that holds the filename? Sorry, I am relatively new to R. This is kinda baffling me a bit. Any help is appreciated..
This doesn't work because the default separator in paste
is a space. So you need to set sep=""
, use paste0
, or use file.path
.
# paste with sep=""
inputFile <- paste('./public-transportation/',
'san-francisco/passenger-count.csv', sep="")
# paste0
inputFile <- paste0('./public-transportation/',
'san-francisco/passenger-count.csv')
# file.path
inputFile <- file.path('./public-transportation/',
'san-francisco/passenger-count.csv')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.