r - Loop to replace "x" in whole code with list of different replacements -
i'm new r , i'm little stuck right now. so, wrote code looks (this beginning):
# load eur files setwd(eur) filenames <- list.files(path = eur) mscieur <- do.call("rbind", lapply(filenames, read.csv, header = true, sep = ";"))
now need run code several times different currencies, question is: there way run same code multiple times , first time runs uses "eur" next time replaces "eur" in code "usd" etc. or need copy paste whole code , replace "eur" "usd" manually?
thx took time read :)
try for
loop, can set different working directories , store data inside list:
curr.name <- gsub(x = list.dirs('.', recursive=false), pattern = "./", replacement ="") curr <- paste(getwd(), curr.name, sep = "/") ___________________________________________________________________________________________ msci <- list() for(i in 1:length(curr)){ setwd(curr[i]) filenames <- list.files(path = curr[i]) msci[[i]] <- do.call("rbind", lapply(filenames, read.csv, header = true, sep = ";")) } names(msci) <- curr.name ___________________________________________________________________________________________ # other way for(i in 1:length(curr)){ setwd(curr[i]) filenames <- list.files(path = curr[i]) assign(curr.name[i],do.call("rbind", lapply(filenames, read.csv, header = true, sep = ";"))) }
Comments
Post a Comment