# Monthly Archives: February 2008

## Find type of variables in a data frame

February 20, 2008
By

sapply(a,class) gives type of field (character, numeric, or factor) for each variable in the data frame a.

## A wraper function to convert coda files into a BUGS object

February 11, 2008
By

I used to fit Bayesian model using WinBUGS via R a lot. But now I am more and more prone to run models on OpenBUGS directly. I have document the reason why I like OpenBUGS and wrote a auto OpenBUGS function here. In short, I like to be able to know wha...

## A wraper function to convert coda files into a BUGS object

February 11, 2008
By

I used to fit Bayesian model using WinBUGS via R a lot. But now I am more and more prone to run models on OpenBUGS directly. I have document the reason why I like OpenBUGS and wrote a auto OpenBUGS function here. In short, I like to be able to know wha...

## R graph with two y-axes

February 4, 2008
By

I’ve been asked how to do this several times, so I thought it might help to put an example online. x <- 1:5 y1 <- rnorm(5) y2 <- rnorm(5,20) par(mar=c(5,4,4,5)+.1) plot(x,y1,type="l",col="red") par(new=TRUE) plot(x, y2,,type="l",col="blue",xaxt="n",yaxt="n",xlab="",ylab="") axis(4) mtext("y2",side=4,line=3) legend("topleft",col=c("red","blue"),lty=1,legend=c("y1","y2"))

## R graph with two y-axes

February 4, 2008
By

I’ve been asked how to do this several times, so I thought it might help to put an example online. x <- 1:5 y1 <- rnorm(5) y2 <- rnorm(5,20) par(mar=c(5,4,4,5)+.1) plot(x,y1,type="l",col="red") par(new=TRUE) plot(x, y2,,t...

## Drop unused factor levels

February 4, 2008
By

When creating a subset of a dataframe, I often exclude rows based on the level of a factor. However, the "levels" of the factor remain intact. This is the intended behavior of R, but it can cause problems in some cases. I finally discovered how to clean up levels in this post to R-Help. Here is an example:>...

## Drop unused factor levels

February 4, 2008
By

When creating a subset of a dataframe, I often exclude rows based on the level of a factor. However, the "levels" of the factor remain intact. This is the intended behavior of R, but it can cause problems in some cases. I finally discovered how to clean up levels in this post to R-Help. Here is an example: >...

## R package: codetools

February 4, 2008
By

Since the release of R_2.6.0, R package developers were advised to use the codetools" package to check potential bugs. However, as I am not familiar with computer language, I found the warning messages a bit confusing. For example:> checkUsage(glm.fit): no visible binding for global variable ‘n’I don't understand what it really means. Apparently, `n' was not globally defined but...