Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich is the best method to apply a script repetitively to n .csv files in R?
    primarykey
    data
    text
    <p><strong>My situation</strong>:</p> <ol> <li>I have a number of csv files all with the same suffix pre .csv, but the first two characters of the file name are different (ie AA01.csv, AB01.csv, AC01.csv etc)</li> <li>I have an R script which I would like to run on each file. This file essentially extracts the data from the .csv and assigns them to vectors / converts them into timeseries objects. (For example, AA01 xts timeseries object, AB01 xts object)</li> </ol> <p><strong>What I would like to achieve</strong>:</p> <ol> <li>Embed the script within a larger loop (or as appropriate) to sequentially run over each file and apply the script</li> <li>Remove the intermediate objects created (see code snippet below)</li> <li>Leave me with the final xts objects created from each raw data file (ie AA01 to AC01 etc as Values / Vectors etc)</li> </ol> <p>What would be the right way to embed this script in R? Sorry, but I am a programming noob! </p> <p>My script code below...heading of each column in each CSV is DATE, TIME, VALUE</p> <pre><code> # Pull in Data from the FileSystem and attach it AA01raw&lt;-read.csv("AA01.csv") attach(AA01raw) #format the data for timeseries work cdt&lt;-as.character(Date) ctm&lt;-as.character(Time) tfrm&lt;-timeDate(paste(cdt,ctm),format ="%Y/%m/%d %H:%M:%S") val&lt;-as.matrix(Value) aa01tsobj&lt;-timeSeries(val,tfrm) #convert the timeSeries object to an xts Object aa01xtsobj&lt;-as.xts(tsobj) #remove all the intermediate objects to leave the final xts object rm(cdt) rm(ctm) rm(aa01tsobj) rm(tfrm) gc() </code></pre> <p>and then repeat on each .csv file til all xts objects are extracted.</p> <p>ie, what we would end up within R, ready for further applications are:</p> <pre><code>aa01xtsobj, ab01xtsobj, ac01xtsobj....etc </code></pre> <p>any help on how to do this would be very much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload