r里面的各种格式化输出

一种是类似于c语言中的sprintf(),譬如:


year = "2008"

mnth = "1"

day = "31"

url = sprintf("https:.../KBOS/%s/%s/%s/DailyHistory.html", year, mnth, day)

#[1] "https:.../KBOS/2008/1/31/DailyHistory.html"                                                                                                                                        

有关这个doc可以参考这里:document

还有一种是glue,但是你必须要加载

year = "2008"

mnth = "1"

day = "31"

url=glue("https:.../KBOS/{year}/{mnth}/{day}/DailyHistory.html")

url #> https:.../KBOS/2008/1/31/DailyHistory.html

还有一种是加载stringr 的这个package

year = "2008"

mnth = "1"

day = "31" stringr::str_interp("https:.../KBOS/${year}/${mnth}/${day}/DailyHistory.html")

最后一个是paste0,就是一种方法,但是你必须要先把他存成一个variable,不可以直接引用

files1 <- paste0('data0', 1:9, '.csv')

files2 <- paste0('data', 10:100, '.csv') file_names <- c(files1, files2)

你可能感兴趣的:(r里面的各种格式化输出)