r

R:lattice.qq How do I do a multi-panel plot of treatment[x] vs control?

I have a dataframe that looks like this: str(Data) 'data.frame': 11520 obs. of 29 variables: $ groupname : Factor w/ 8 levels "Control","Treatment1",..: 1 1 1 1 1 1 1 1 1 1 ... $ fCycle : Factor w/ 2 levels "Dark","Light": 2 2 2 2 2 2 2 2 2 2 ... $ totdist : num 0 67.5 89.8 109.1 58.3 ... #etc. I can do a single plot o...

What are the advantages/disadvantages between R and MATLAB with respect to Machine Learning?

I am beginning some studies into machine learning and it seems these two are often used in this field. They seem very similar, so how would one decide which is best to use? ...

Reduced row echelon form

Is there a function in R that produces the reduced row echelon form of a matrix?. This reference says there isn't. Do you agree? ...

deleting unwanted xml nodes

I have a bunch of .xml files with nodes that are causing uncessesary complications. I would like to remove these nodes but ensure that thier children are preserved (not the heirarchical structure but the data). Eventually I want to take the data from each .xml and build a dataframe. It seems like xmlTreeParse along with xmlToList will...

shebang line not working in R script

I have the following script #!/usr/bin/Rscript print ("shebang works") in a file called shebang.r. When I run it from command line using Rscript it works $ Rscript shebang.r but when I run it from the command line alone $ shebang.r It doesn't work. shebang.r command not found. If I type (based on other examples I've seen) $ ....

gunzip a file stream in R?

I'm trying to create an R API for StackOverflow. The output is gzipped. For example: readLines("http://api.stackoverflow.com/0.9/stats/", warn=F) [1] "\037‹\b" ...

Loops inefficiency in R

Good morning, I have been developing for a few months in R and I have to make sure that the execution time of my code is not too long because I analyze big datasets. Hence, I have been trying to use as much vectorized functions as possible. However, I am still wondering something. What is costly in R is not the loop itself right? I m...

R: Forecast package: Automatic algorithm for composite model involving ETS and AR

Hey, I would like to write a code involving automatic selection of a best composite model using ETS as well as autoregressive models. What is the criteria I should base my selection on? Also if I'm using the auto.arima function for deducing number of AR terms and corresponding coefficients from the forecast package in R, does my input ...

Getting legend coloring in an empty ggplot

Before presenting the actual data, I would like to make a plot identical to the one with data but then without the data points in there. This helps me in explaining how to interpret such a plot without distracting the audience with the actual data that will be in the plot. So in the code below I would basically want to exchange the geom...

Displaying errors with sweave

I'm writing some R notes with Sweave and would like to show common errors. For example, <<echo=TRUE, eval=TRUE>>= x = 5 #Case matters! x*X @ However when sweaving, the document won't compile due to the R error. Is there any way to make sweave compile and show the (nicely formated) error? ...

Problem with R console

I have a little problem with my R console recently. When I start R ("C:\Program Files\R\R-2.8.1\bin\Rgui.exe"), the cursor immediately starts in INSERT mode (thick state). Then I have to press Insert and toggle it to normal mode (thin state). As soon as I write a command line and hit Enter, the cursor again toggles to INSERT mode. I don'...

Determining different rows between two data sets in R

I have two data files in tab separated CSV format. The files are in the following format: EP Code EP Name Address Region ... 101654 Alpha York Street Northwest ... 103628 Beta 5th Avenue South ... EP codes are unique. What I want to do is to compare two files with respect to EP codes, determine the...

Refer to relative rows in R

I know this answer must be out there, but I can't figure out how to word the question. I'd like to calculate the differences between values in my data.frame. from this: f <- data.frame(year=c(2004, 2005, 2006, 2007), value=c(8565, 8745, 8985, 8412)) year value 1 2004 8565 2 2005 8745 3 2006 8985 4 2007 8412 to this: year ...

Error when running library(ggplot2)

Hello I just updated to R 2.11.1 and after installing ggplot2, I tried library(ggplot2) and got Loading required package: proto Loading required package: grid Loading required package: reshape Loading required package: plyr Loading required package: digest Error in eval(expr, envir, enclos) : could not find function ...

Naming points of a R graphic

Hello, I would like to name some points of a R graphic, got from the basic function plot(). More precisely I have a 2-dimensional parametric function t -> (a(t),b(t)), and I plot the points (a(t),b(t)). I would like to print the value of t corresponding to each point. Thank you ...

Why do vector indices in R start with 1, instead of 0?

What is the reason that vector indices in R start with 1, instead of the usual 0? Example: > arr<-c(10,20) > arr[0] numeric(0) > arr[1] [1] 10 > arr[2] [1] 20 Is it just that they want to store extra information about the vector and didn't know where to store it except as the vector's first element? ...

Read SPSS file into R

Hi All, Probably a basic answer. I am trying to learn R and want to bring in an SPSS file, which I can open in SPSS. I have tried using read.spss from foreign and spss.get from Hmisc. Both error messages are the same. Here is my code: ## install.packages("Hmisc") library(foreign) ## change the working directory getwd() setwd('...

Algorithm to determine proper divisors

Hi all, I am interested in finding the numbers that exhibit the property of having the sum of their proper divisors equal to the number. The first example is 6, where the proper divisors are 1 + 2 + 3 = 6. I wrote the following code in R, but I feel it is pretty inefficient and can be improved upon significantly. propDivisor <- func...

XTS size limitation

Good morning, My question saga continues about R. I have been working on large datasets lately (more than 400 thousands lines). So far, I have been using XTS format, which worked fine for "small" datasets of a few tenth of thousands elements. Now that the project grows, R simply crashes when retrieving the data for the database and p...

How to adjust the line width of colour in geom_box for ggplot2?

As title, I think the default line width for the border of geom_box is a bit too thick, is there a way of modifying it? Thanks! ...