Category: R

  • Source a bunch of files under given folders and/or subfolders

    I wrote a function sourceDir() that can source all the functions under given folders and/or subfolders. This function is very much like “Set Path” in Matlab.Please visit this page to obtain the update to dated version. https://github.com/feng-li/flutils/blob/master/sourceDir.R To use it more efficiently, I suggest you put the function at some place, e.g. ~/workspace/R_utils/sourceDir.R, and write…

  • How to prevent dropping dimensions in a matrix/array?

    When you create a matrix in the usual way like this, > a <- matrix(rnorm(10),2,5) > a        [,1]      [,2]       [,3]       [,4]       [,5] [1,]  1.3488918 0.6225795 -0.7444514  1.3130491  1.7877849 [2,] -0.2385392 0.5656759  0.9037435 -0.2217444 -0.2656875 the dimension dropped after picking up a single row or column in this way, > b <- a[,1] > b…

  • How to crop an eps file?

    When you create a figure (in e.g. eps format) with R, the margins around the main context are always too wide. To save the space in the final documents, e.g. LaTeX generated pdf file. I have figured out two ways of reducing the margins.If you just want to shrink the white margin of an eps…