r - Change file name when using write.table() according to the name of the third column in data frame -



r - Change file name when using write.table() according to the name of the third column in data frame -

i wrote script in r merges , modifies csv info , saves resulting info frame using write table(). when saves file adds current date name of file. 3rd column of resulting info frame country specific, wondering if there way include in file name using write.table name of country depending on country code (name of 3rd column).

for example, if name of 3rd column "it", want add together "italy" name of csv file using write.table.

import list of country names , codes r: (it wise @ top of script: outside processing loop dont read in info on , on each dataset beingness written out .csv. rest of code goes before current write.table command

library(rcurl) csv_src <- geturl("https://raw.githubusercontent.com/umpirsky/country-list/master/country/cldr/en/country.csv") world <- read.csv(text=csv_src, header=t)`

get name of 3rd column in info country codes:

countrycode <- colnames(yourdata)[3]

extract corresponding country name:

country_idx <- grep(pattern=countrycode, x=world$iso, ignore.case = true) country <- world$name[country_idx]

attach country name csv filename (replace "..." whatever other tags want appended output filename. otherwise remove "...")

csv_name <- paste0("...",country, ".csv")

write out info file:

write.table(x=yourdata, file=csv_name)

good luck :-)

r

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -