Monday 15 February 2010

r - Obtaining results from operations on multiple files as a two-column matrix -


I am using a loop for loop through files in a directory. Then I make a set of processing data on each file and write a matrix with 10 rows. This is my code. (1 in I: length (testdata)) {MAE [1, i] = abs (predict data $ [i] - testData [i])}

  / code>  

Now I want to do the following:

  • Add rows to this matrix
  • Write it as a value
  • File name Two columns matrix with different columns and the value in the form of the second column
  • Sort it by value (no file name)
  • Access it globally (i.e., this For matrix The number of rows will be the total number of files in the directory (dynamically specified what i mean). How can I get this functionality?

    It is difficult to give a comprehensive answer because there is no instance in general, however, I use the list.files () vector of all the files To get, and then write that function Is not that satisfy you have mathematics on each file. This function may look something like this.

      func.file_math & lt; - function (file.name) {& lt; Insert file operation & gt; Return (You can run it on all content by using the list (file.name = file.name, number = number))}  

    sapply () Your file.list () . Once done, you can simply use the do.call () and rbind.data.frame to get the data frame of the results.

      Your files & lt; - list.files ("/ some / path /") file_math & lt; - sapply (X = yourfiles, FUN = func.file_math, simplify = FALSE, USE.NAMES = TRUE) file_math.df & lt; - Please .Call (What is = RBIDDETEframe, args = file_math)  

No comments:

Post a Comment