title: How to write a for loop to read multiple csv files into R and subset the data to make clean dataframes for ggplots?
body: <p>I am trying to read multiple csvs into R and then subset those csvs by removing columns I don't need using the 'subset' function.  i am trying to setup a for loop in r that I can add functions or calculation to a list of csvs in order to produce dataframes for ggplots or stat analysis later. (I currently have tidyverse, dplyr, and ggplot2 installed). Right now I just want to subset the csvs and then create a dataframe from the subsetted data.</p>
  
  <p>I used a for loop to successfully read multiple csvs into separate dataframes by setting a working directory, creating a list of csvs, then reading them into dataframes.  This currently outputs a dataframe for each csv named after the original filename:</p>
  
  <pre><code>filenames &lt;- gsub("\\.csv$","", list.files(pattern="\\.csv$"))
  
  
  for(i in filenames){
       assign(i, read.csv(paste(i, ".csv", sep="")))}
  </code></pre>
  
  <p>Then I realized I wanted to subset these data before putting them into the dataframes in order to avoid some repetitive code later; however, I am getting an error each time I tried to add a subset function to the for loop.  This is what I currently have:</p>
  
  <pre><code>for(i in filenames){
    read.csv(i)
    subset(i, select = c("names", "of columns", "I want"))
    assign(i, read.csv(paste(i, ".csv", sep="")))
  }
  </code></pre>
  
  <p>I receive a "no such file or directory error". I'm sure I'm missing something obvious since my R foundation is poor, but any help or advice to make this work would be appreciated.  The subset function has worked for me in the past but I had to write out a new line for each dataframe and would like to avoid that by using a list and for loop or some other method.</p>
  
  <p>Thank you</p>