I've got several csv files that all have this format:
xyz site 2.1 tex1 15.67 tex2 32.111 ny31 I want to import these files into R. Like this:
df_list <- list.files('./usa_data') dfs <- lapply(df_list, import_function) What I want the import_function to do is to take a part of the name of the csv file and paste it instead of the first column name (xyz). My csv names have this format:
usa_low_dollars_270_1.csv usa_high_euros_250_2.csv usa_low_gbp_240_1.csv I want to extract the currency (the third component of the name), combine it with the word 'median' and rename the first column like this:
dollars_median site 2.1 tex1 15.67 tex2 32.111 ny31 # or euros_median site 2.1 tex1 15.67 tex2 32.111 ny31 # etc