简体   繁体   中英

Loop function for vector of character strings in R

I need to loop the following function to output separate plots for all values in a vector of character strings. These values are three letter country codes, with the example of the single Tanzania ( "TZA" ) shown below. The vector of country codes can be specified by CountryList$Country

 tiff("TZA_vanda.tiff", units="in", width=8, height= 6, res=120)
    tscsPlot(a.out2, cs = "TZA", var = "vanda")
    dev.off()

Not tested, obviously, but perhaps something along these lines?

for (i in unique(CountryList$Country)) {
  tiff(sprintf("%s_vanda.tiff", i), units="in", width=8, height= 6, res=120)
  tscsPlot(a.out2, cs = i, var = "vanda")
  dev.off()
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM