Blog Archives

x[[c(5,3)]]

April 2, 2013
By
x[[c(5,3)]]

An R tip: Did you know that x] is the same as x]]? I should make more thorough use of this. In the help file for ] is equivalent to alist]...] providing all but

Read more »

Curved arrows in R

October 10, 2012
By
Curved arrows in R

I briefly investigated how to draw curved arrows in R. Here’s a small piece of the figure that I ultimately created: A google search for “curved arrows in R” revealed three options: curvedarrow in the diagram package The internal function igraph.Arrows within the igraph package (mentioned by Gabor Csardi in R help) Using xspline for

Read more »

Learning a new language

June 21, 2012
By
Learning a new language

It had been a very long time since I’d tried to learn a new programming language. I started C in 1987, S in 1992, and Perl in 1997, but nothing really new in the subsequent 15 years. A friend now has me doing D, wanting to find time to learn ruby, and, most recently, playing

Read more »

A course in statistical programming

May 25, 2012
By
A course in statistical programming

Graduate students in statistics often take (or at least have the opportunity to take) a statistical computing course, but often such courses are focused on methods (like numerical linear algebra, the EM algorithm, and MCMC) and not on actual coding. For example, here’s a course in “advanced statistical computing” that I taught at Johns Hopkins

Read more »

Should I be nice?

May 18, 2012
By
Should I be nice?

I got the following email. Subject: i have a question? Date: May 18, 2012 7:57:56 AM CDT how can i enter the data of QTL analysis. That was the whole thing. I presume that the writer wishes to use my R/qtl software. I could probably respond helpfully (for example, “See the sample data files and

Read more »

as.character() for rownames()

March 22, 2012
By
as.character() for rownames()

Rainer pointed out, in response to my post, Row names in data frames: Beware of 1:nrow, that if I’d used rownames(x) <- as.character(1:3) rather than rownames(x) <- 1:3, I wouldn’t have had the problem I’d seen. If you type rownames(x) you see the same result as rownames(z), and is.character(rownames(x)) and is.character(rownames(z)) both return TRUE, but

Read more »

Row names in data frames: beware of 1:nrow

March 21, 2012
By
Row names in data frames: beware of 1:nrow

I spent some time puzzling over row names in data frames in R this morning. It seems that if you make the row names for a data frame, x, as 1:nrow(x), R will act as if you’d not assigned row names, and the names might get changed when you do rbind. Here’s an illustration: As

Read more »

Halloween 2011 count

October 31, 2011
By
Halloween 2011 count

We don’t get many kids seeking candy at our house. I’m not sure if there just aren’t many kids in the neighborhood, or if it’s our location (next to the pond, with a big gap before the next house). I decided to keep track. As usual, we bought a huge bag of candy, and we

Read more »

Ghastly R code

September 27, 2011
By
Ghastly R code

My R package, R/qtl, contains about 33k lines of R code (and 21k lines of C code). Some of it is quite good; some of it is terrible. Here’s another example of the terrible. I’ve long needed to revise the function scantwo, for performing a two-dimensional genome scan for pairs of loci. I was looking

Read more »

Gamified

September 26, 2011
By
Gamified

Barry Rowlingson gave an interesting talk at UseR 2011, “Why R-help must die!” He suggested the Q-and-A type sites Stack Overflow (on programming) and Cross Validated (on statistics), both part of Stack Exchange. An interesting feature of these sites is that, in addition to voting up and down on the questions and answers, one accrues

Read more »