Posts Tagged ‘ code ’

Why hadn’t I written a function for that?

July 17, 2014
By

I’m often typing the same bits of code over and over. Those bits of code really should be made into functions. For example, I’m still using base graphics. (ggplot2 is on my “to do” list, really!) Often some things will be drawn with a slight overlap of the border of the plotting region. And in […]

hipsteR: re-educating people who learned R before it was cool

May 15, 2014
By

This morning, I started a tutorial for folks whose knowledge of R is (like mine) stuck in 2001. Yesterday I started reading the Rcpp book, and on page 4 there’s an example using the R function replicate, which (a) I'd never heard before, and (b) is super useful. I mean, I often write code like […]

Further points on crayon colors

May 9, 2014
By

I saw this great post on crayola crayon colors at the Learning R blog, reproducing a nice graph of the Crayola crayon colors over time. (Also see this even nicer version.) The Learning R post shows how to grab the crayon colors from the wikipedia page, “List of Crayola crayon colors,” directly in R. Here’s […]

Two more points about crayon colors

May 8, 2014
By

If you want to use crayon colors in R but you don’t want to rely on my R/broman package, you can just grab the code. Copy the relevant lines from the R/brocolors.R file: I spent a bit of time thinking about how best to sort the colors in a meaningful way, for the plot_crayons() function. […]

“[” with the apply() functions, revisited

April 30, 2014
By

I’d mentioned in the fall that one could use "[" in the apply-type functions, like this: I just realized that you can use this with matrices, too. If you have a list of matrices, you can pull out rows and columns with this technique. As you can see, my data isn't “tidy.”

Summary stats for ABC

September 1, 2013
By
$Summary stats for ABC$

Introduction In the previous post I gave a very brief introduction to ABC, including a simple example for inferring the parameters of a Markov process given some time series observations. Towards the end of the post I observed that there were (at least!) two potential problems with scaling up the simple approach described, one relating […]

Summary stats for ABC

September 1, 2013
By
$Summary stats for ABC$

Introduction In the previous post I gave a very brief introduction to ABC, including a simple example for inferring the parameters of a Markov process given some time series observations. Towards the end of the post I observed that there were (at least!) two potential problems with scaling up the simple approach described, one relating […]

“[” and “[[” with the apply() functions

August 20, 2013
By

Did you know you can use "[" and "[[" as function names for subsetting with calls to the apply-type functions? For example, suppose you have a bunch of identifier strings like "ZYY-43S-CWA3" and you want to pull off the bit before the first hyphen ("ZYY" in this case). (For code to create random IDs like […]

August 6, 2013
By

The other day, there was a bit of a twitter conversation about qqline in R. It made me think: how exactly is the line produced by qqline chosen? I seemed to recall that the line was through the first and third quartiles. An advantage of R is that you can just type the name of […]

Learning to code in R

April 26, 2013
By

It used to be that the one of the first decisions to make when learning to program was between compiled (e.g. C or FORTRAN) and interpreted (e.g. Python) languages. In my opinion these days one would have to be a masochist to learn with a compiled language: the extra compilation time and obscure errors are […]