Contributed GNU-R Code

Use the comments box here to contribute GNU-R functions/code that you may have prepared. The idea is to use this space to archive interesting little snippets of codes that may be useful to others.

Please note that all “<” in your codes will have to be replaced by a “&lt;” (without quotes) and all “> ” will have to be replaced by a “&gt;”. This is to distinguish them from html/css tags.

Please provide your e-mail so that people interested in using your code could contact you if needed. Comments will be moderated only to prevent spam.




Comments RSS
  1. Chandan Mukherjee

    Here is a function ‘scatterbox’ which plots y against x along with the boxplots of them and the lowess fit to the scatterplot.
    scatterbox <- function (x, y, …)
         def.par <- par(no.readonly = TRUE)
         n <- length(x)
         xbox <- boxplot(x, plot = FALSE)
         ybox <- boxplot(y, plot = FALSE)
         xrange <- c(min(x), max(x))
         yrange <- c(min(y), max(y))
         nf <- layout(matrix(c(2, 0, 1, 3), 2, 2, TRUE), c(6, 1),
          c(1, 6), TRUE)
         par(mar = c(5, 5, 0, 0))
         plot(x, y, xlim = xrange, ylim = yrange, …)
         par(mar = c(0, 5, 1, 1))
         bxp(xbox, outline=FALSE, axes=FALSE, horiz=TRUE)
         par(mar = c(5, 0, 1, 1))
         bxp(ybox, outline=FALSE, axes=FALSE)
    An example is
    The output looks like this

  2. VR

    Here is a function that gives class (integer,numeric,character,factor,etc) of each variable in your dataframe. I didn’t know if there is already a function that does the job, so I just wrote it for myself. Clumsily done, but works. If you can improve it, post improved version.

    vattr<-function(X) {
         for (i in 2:dim(X)[2]) {c(Xa,class(X[,i]))->Xa}

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: