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 “<” (without quotes) and all “> ” will have to be replaced by a “>”. 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.
V.
2 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.
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))
low<-lowess(x,y)
nf <- layout(matrix(c(2, 0, 1, 3), 2, 2, TRUE), c(6, 1),
c(1, 6), TRUE)
layout.show(nf)
par(mar = c(5, 5, 0, 0))
plot(x, y, xlim = xrange, ylim = yrange, …)
lines(low$x,low$y)
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)
par(def.par)
}
An example is
x<-sort(rnorm(100))
y<-sort(rt(100,3))
source(“~/scatterbox.R”)
scatterbox(x,y)
The output looks like this
Comment by Chandan Mukherjee — June 25, 2007 #
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) {class(X[,1])->Xa
for (i in 2:dim(X)[2]) {c(Xa,class(X[,i]))->Xa}
data.frame(variables=names(X),class=Xa[1:length(Xa)])
}
Comment by VR — February 19, 2008 #