r

What is your favorite R debugging trick?

I've recently started using browser() in function definitions for debugging (a great tool!). I feel like print() debugging has been slowing my learning curve of built-in debugging tools. What are some others I've been missing? ...

Combining 3D/2D plots

I'm trying to make a visualization that looks like this . The idea is to have a 3D surface plot overlapping a 2d representation of a surface. I can build arbitrary surfaces/polygon shapes (as in http://addictedtor.free.fr/graphiques/graphcode.php?graph=135 ) and I can make the respective 2D plot. What I don't seem to be able to figure ...

Avoiding loops in R

Hello, I have decided to learn R. I am trying to get a sense of how to write "R style" functions and to avoid looping. Here is a sample situation: Given a vector a, I would like to compute a vector b whose elements b[i] (the vector index begins at 1) are defined as follows: 1 <= i <= 4: b[i] = NaN 5 <= i <= length(a): b[i] = mean(a[i...

making the subversion revision number visible in my R scripts

I'm putting this thing in my source(s)... (right, for now it's just one, plus the test scripts). REVISION = (function(x) substring(x, first=7, last=nchar(x)-2))("$Rev: 8727 $") but how do "real" R programmers do? ...

How to point to a directory in an R package?

I am making my first attempts to write a R package. I am loading one csv file from hard drive and I am hoping to bundle up my R codes and my csv files into one package later. My question is how can I load my csv file when my pakage is generated, I mean right now my file address is something like c:\R\mydirectory....\myfile.csv but after...

How to format axes in R, year and months

I have the following dataset 1890 mar 0.4 1890 apr 0.8 1890 may 1.0 ... 1989 jan 0.2 1989 feb 0.4 1989 mar 0.5 How can I make a line plot in R with on the x-axis the year, displayed every 5 years? My problem is not so much making the plot, but getting to display only the years I want, and place them on the beginning of that year. So ...

Unexpected value for length of a vector in R

I have the character vector below a = c("2009-07-31 18:00:33", "2009-07-31 18:00:38", "2009-07-31 18:00:43", "2009-07-31 18:00:49", "2009-08-01 01:58:49", "2009-08-01 01:53:16", "2009-08-01 08:04:13", "2009-08-01 16:16:13") I want to convert this to time objects so I do this: b = strptime(a, "%Y-%m-%d %H:%M:%S") Why do a and b ha...

getting the highest subversion revision in my `R CMD build` filename

a question following making-the-subversion-revision-number-visible-in-my-r-scripts R CMD build PKG creates a file named as Package_Version.tar.gz according to the fields in DESCRIPTION. not only isn't the strictly sequential numbering coming from svn very practical here, but its $REV: number $ format does not respect the number.numb...

Getting R plots into LaTeX?

I'm a newbie to both R and LaTeX and have just recently found how to plot a standard time series graph using R and save it as a png image. What I'm worried about is that saving it as an image and then embedding it into LaTeX is going to scale it and make it look ugly. Is there a way to make R's plot() function output a vector graphic an...

How to create a sensible Hilbert Spectrum plot with R (computing environment)

I am using the EMD package for R. This package has a spectrogram function for displaying a Hilbert Spectrum (calculated with hilbertspec). The output however, is really vague and black-white. This function does not seem to have an option for outputting color images. How can I get the spectrum displayed clearly and if possible in color. ...

basic SNA in R? - How to load network data

A few years back I used UCINET for some social network analysis. Theese days I'd like to use SNA again - but this time I prefer a unified analysis framework - which for me is R. I have looked at the sna and statnet documentation but am a bit overwhelmed. What I'd like to do: First: Load an bipartite/incidence matrix pulled directly fro...

Plotting a 3d surface plot with contour map overlay, using R

I have a 3-tuple data set (X,Y,Z points) that I want to plot using R. As the title of my question states, I want to create a surface plot from the data, and superimpose a contour map on the surface plot, so as to create the impression of the contour map being the "shadow" or projection from the surface plot. The contour map is to appear...

Angle between two vectors in R

What the most efficient way in the programming language R to calculate the angle between two vectors? ...

qplot and anti-aliasing in R

I am using ggplot2 library and am working with the qplot command I know I can save my output as an anti-aliased image file by using the following command after my qplot ggsave(file="filename.png") But how about my LCD display? is there any way to see a plot on the monitor as anti-aliased grpah? ...

rbind.zoo doesn't seem create consistent zoo object

I want to rbind.zoo two zoo object together. When I was testing I came across the following issue(?)... Note: The below is an example, there is clearly no point to it apart from being illustrative. I have an zoo object, call it, 'X'. I want to break it into two parts and then rbind.zoo them together. When I compare it to the origina...

Weights from linear SVM model (in R)?

Using kernlab I've trained a model with code like the following: my.model <- ksvm(result ~ f1+f2+f3, data=gold, kernel="vanilladot") Since it's a linear model, I prefer at run-time to compute the scores as a simple weighted sum of the feature values rather than using the full SVM machinery. How can I convert the model to something li...

[R] GLM with autoregressive term to correct for serial correlation

Hi I have a stationary time series to which I want to fit a linear model with an autoregressive term to correct for serial correlation, i.e. using the formula At = c1*Bt + c2*Ct + ut, where ut = r*ut-1 + et (ut is an AR(1) term to correct for serial correlation in the error terms) Does anyone know what to use in R to model this? Than...

R code examples/best practices

I'm new to R and having a hard time piecing together information from various sources online related to what is considered a "good" practice with writing R code. I've read basic guides but I've been having a hard time finding information that is definitely up to date. What are some examples of well written/documented S3 classes? How a...

R: RUnit testing uninstalled package

I am following the hints to this question, but I'm impatient and I would like to run my tests more quickly, without having to wait for the 30+ checks that R CMD check src invokes before checking tests. what I thought I could do was to add a --standalone option to the doRUnit.R suggested in that R-wiki page so that I could run the uni...

What does the @ symbol mean in R?

In packages like marray and limma, when complex objects are loaded, they contain "members variables" that are accessed using the @ symbol. What does this mean and how does it differ from the $ symbol? ...