haotu : an open lab notebook


Plotting R squared in R with significant digits

Filed under: R — S @ 09:44

I found it exceedingly difficult to plot the text R2=foo where foo is an object of a number. I also found that if you want to plot numbers with trailing zeros for significant digits it is also difficult… unless you are really good with R… so here is what I eventually did

 substitute(R^2 == Rs, list(Rs = sprintf(signif(summary(lm.obj)$r.squared,digits=2),fmt="%#.2g")))

in the fmt variable for sprintf change the 2 to a different number to get more or less trailing zeros…


Exact pattern matching with grep

Filed under: R — S @ 08:53

grep does not do exact pattern matching, thus there is a problem when you want to get the element “foo1” from a list c(“foo1″,foo10″,”foo11”) in that grep would return the index c(1,2,3). Here is a work around.



Build multiPhylo object with a for loop

Filed under: Uncategorized — S @ 07:17

I have had problems with the concatenate function (c.phylo) for multiPhylo objects. I have found that the object doubles in size with each loop. Here is a work around:

 for(i in 1:l)

Blog at WordPress.com.