r

How to center an R plot after removing axis labels

I'm working on visualizing a matrix in R (almost exactly like http://reference.wolfram.com/mathematica/ref/MatrixPlot.html), and I've been using image(<matrix>,axes=FALSE) to draw the picture. However, I noticed that with the y-axis turned off, the plot isn't centered--the space is still there for the axis ticks + label. I can finag...

Rreport/LaTeX quality output package

I'm looking for some LaTeX template for creating quality output. On R-bloggers I've bumped on Frank Harrel's Rreport package. Due to my quite modest LaTeX abilities, only a user-friendly (and noob-friendly) interface should suffice. Here's a link to an official website. I'm following the instructions, but I cannot manage to install an ap...

What is an efficient method for partitioning and aggregating intervals from timestamped rows in a data frame?

From a data frame with timestamped rows (strptime results), what is the best method for aggregating statistics for intervals? Intervals could be an hour, a day, etc. There's the aggregate function, but that doesn't help with assigning each row to an interval. I'm planning on adding a column to the data frame that denotes interval a...

Coding the R-ight way - avoiding the for loop

I am going through one of my .R files and by cleaning it up a little bit I am trying to get more familiar with writing the code the r-ight way. As a beginner, one of my favorite starting points is to get rid of the for() loops and try to transform the expression into a functional programming form. So here is the scenario: I am assemblin...

Strange findFn malfunction

I noticed a strange malfunction in using findFn function (library sos) and I can't find out the source. While it works fine on my Windows XP pc, it does not on my Vista one. library (sos) findFn("randomization test") # in both finds 72 results findFn("{randomization test}") # In XP finds 19 or about so, but in Vista whenever I use {} ...

How can I use R (Rcurl/XML packages ?!) to scrape this webpage ?

Hi all, I have a (somewhat complex) web scraping challenge that I wish to accomplish and would love for some direction (to whatever level you feel like sharing) here goes: I would like to go through all the "species pages" present in this link: http://gtrnadb.ucsc.edu/ So for each of them I will go to: The species page link (for ex...

how do I specify random factors in R ?

Hi guys , How do I specify random factors in R ? If I have a factor x1 which is supposed to be random , can I try something like this ? lm(y ~ x1, data = p) ...

ANOVA with 3 fixed factors in R

Im trying to run a model with a response variable p and 3 fixed factors to get ANOVA. this is how my code looks like : #run it as 3 fixed factor model p1=c(37,38,37,41,41,40,41,42,41) p2=c(42,41,43,42,42,42,43,42,43) p3=c(30,31,31,31,31,31,29,30,28) p4=c(42,43,42,43,43,43,42,42,42) p5=c(28,30,29,29,30,29,31,29,29) p6=c(42,42,43,45,45...

R ggplot2: Arrange facet_grid by non-facet column (and labels using non-facet column)

I have a couple of questions regarding facetting in ggplot2... Let's say I have a query that returns data that looks like this: (note that it's ordered by Rank asc, Alarm asc and two Alarms have a Rank of 3 because their Totals = 1798 for Week 4, and Rank is set according to Total for Week 4) Rank Week Alarm To...

Converting python objects for rpy2

The following code is supposed to created a heatmap in rpy2 import numpy as np from rpy2.robjects import r data = np.random.random((10,10)) r.heatmap(data) However, it results in the following error Traceback (most recent call last): File "z.py", line 8, in <module> labRow=rowNames, labCol=colNames) File "C:\Python25\lib\...

Faster way to split a string and count characters using R?

I'm looking for a faster way to calculate GC content for DNA strings read in from a FASTA file. This boils down to taking a string and counting the number of times that the letter 'G' or 'C' appears. I also want to specify the range of characters to consider. I have a working function that is fairly slow, and it's causing a bottleneck...

Randomized experiments in R

Here is a simple randomized experiment. In the following code I calculate the p-value under the null hypothesis that two different fertilizers applied to tomato plants have no effect in plants yields. The first random sample (x) comes from plants where a standard fertilizer has been used, while an "improved" one has been used in the pl...

R regex to validate user input is correct.

I'm trying to practice writing better code, so I wanted to validate my input sequence with regex to make sure that the first thing I get is a single letter A to H only, and the second is a number 1 to 12 only. I'm new to regex and not sure what the expression should look like. I'm also not sure what type of error R would throw if this ...

Fastest way to find second (third...) highest/lowest value in vector or column

Hello, R offers max and min, but I do not see a really fast way to find the another value in the order apart from sorting the whole vector and than picking value x from this vector. Is there a faster way to get the second highest value (e.g.)? Thanks ...

How to parse a string (by a "new" markup) with R ?

Hi all, I want to use R to do string parsing that (I think) is like a simplistic HTML parsing. For example, let's say we have the following two variables: Seq <- "GCCTCGATAGCTCAGTTGGGAGAGCGTACGACTGAAGATCGTAAGGtCACCAGTTCGATCCTGGTTCGGGGCA" Str <- ">>>>>>>..>>>>........<<<<.>>>>>.......<<<<<.....>>>>>.......<<<<<<<<<<<<." Say that I wa...

aov define F values computation

Greetings to all This is my model: aov.fit<-aov(Y~A+B+C+D+E+A:C+A:E, data=dat) In summary(aov.fit) all F values are computed by eg MS(A)/MS(Residuals). This is not correct (or what I want), except for F(B) and F(A:E). I suppose P values are not correct either. Can I specify how the F computations will be done? I 'd like them to be lik...

Adding multiple vectors in R

I have a problem where I have to add thirty-three integer vectors of equal length from a dataset in R. I know the simple solution would be Vector1 + Vector2 + Vector3 +VectorN But I am sure there is a way to code this. Also some vectors have NA in place of integers so I need a way to skip those. I know this may be very basic but I am ...

R: how to print a character list from A to Z?

In R, how can I print a character list from A to Z? With integers I can say: my_list = c(1:10) > my_list [1] 1 2 3 4 5 6 7 8 9 10 But can I do the same with characters? e.g. my_char_list = c(A:Z) my_char_list = c("A":"Z") These don't work, I want the output to be: "A" "B" "C" "D", or separated by commas. Thanks. ...

HashMap as return value from Java method in R?

Hi, is it possible to return a HashMap to R with the rJava extension of R? E.g. I have a method in Java, which returns a HashMap and I want this HashMap use in R. I tried: .jcall(javaObj, "Ljava/util/HashMap", "getDbInfoMap") This doesn't work. Do I have to put everything into a String[], that I want to pass to R from Java? Or is th...

[r] Converting unix seconds in milliseconds to POSIXct/POSIXlt

Why do I see a difference when I convert a unix timestamp to datetime object in R? > as.POSIXlt(1268736919, origin="1970-01-01", tz="America/New_York") [1] "2010-03-16 06:55:19 EDT" > as.POSIXct(1268736919, origin="1970-01-01", tz="America/New_York") [1] "2010-03-16 11:55:19 EDT" The result from POSIXlt is actually correct. Also, is...