Blog Archives

R matrices in C functions

December 13, 2008
By

Using the .C() function in R, you can only pass vectors. Since R stores matrices columnwise as vectors anyhow, they can be passed to your C function as vectors (along with the number of rows in the matrix) and then accessed in familiar manner...

Read more »

R matrices in C functions

December 13, 2008
By

Using the .C() function in R, you can only pass vectors. Since R stores matrices columnwise as vectors anyhow, they can be passed to your C function as vectors (along with the number of rows in the matrix) and then accessed in familiar manner...

Read more »

Call C from R and R from C

November 17, 2008
By

Several years ago, while a research associate at the University of Chicago, I had the privilege of sitting in on a course taught by Peter Rossi: Bayesian Applications in Marketing and MicroEconometrics. This course -- one I recommend to anyone at U Chicago who is interested in statistics -- was an incredibly clear treatment of Bayesian...

Read more »

Call C from R and R from C

November 17, 2008
By

Several years ago, while a research associate at the University of Chicago, I had the privilege of sitting in on a course taught by Peter Rossi: Bayesian Applications in Marketing and MicroEconometrics. This course -- one I recommend to anyone at U Chicago who is interested in statistics -- was an incredibly clear treatment of Bayesian...

Read more »

Error capture

May 6, 2008
By

In a recent post to r-sig-ecology, Mike Colvin suggested the following to capture errors within a loop:for (i in 1:1000){fit<-try(lm(y~x,dataset))results<- ifelse(class(fit)=="try-error", NA, fit$coefficients)}

Read more »

Error capture

May 6, 2008
By

In a recent post to r-sig-ecology, Mike Colvin suggested the following to capture errors within a loop:for (i in 1:1000){fit<-try(lm(y~x,dataset))results<- ifelse(class(fit)=="try-error", NA, fit$coefficients)}

Read more »

Plotting contours

March 18, 2008
By
Plotting contours

Plenty of packages allow you to plot contours of a "z" value; however, I wanted to be able to plot a specific density contour of a sample from a bivariate distribution over a plot that was a function of the x and y parameters. The example only plots th...

Read more »

Plotting contours

March 18, 2008
By
Plotting contours

Plenty of packages allow you to plot contours of a "z" value; however, I wanted to be able to plot a specific density contour of a sample from a bivariate distribution over a plot that was a function of the x and y parameters. The example only plots th...

Read more »

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: >...

Read more »

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:>...

Read more »