r

How do I rename an R object?

I'm using the quantmod package to import financial series data from Yahoo. library(quantmod) getSymbols("^GSPC") [1] "GSPC" I'd like to change the name of object "GSPC" to "SPX". I've tried the rename function in the reshape package, but it only changes the variable names. The "GSPC" object has vectors GSPC.Open, GSPC.High, etc. I'd l...

stats::reorder vs Hmisc::reorder

I am trying to get around the strange overlap of stats::reorder vs Hmisc::reorder. Without Hmisc loaded I get the result I want, i.e. an unordered factor: > with(InsectSprays, reorder(spray, count, median)) [1] A A A A A A A A A A A A B B B B B B B B B B B B C C C C C C C C C C C C D D [39] D D D D D D D D D D E E E E E E E E E E E E ...

Howto suppress one command's output in R?

In R I'm looking to suppress the output of one command (in this case, the apply function). Is it possible to do this without using sink()? I've found the described solution below, but would like to do this inline if possible. Danke. http://stackoverflow.com/questions/2501895/how-to-suppress-output-in-r ...

How to change the icon in the title bar in R?

I just installed R 2.11.0-x64 onto my Windows 7 Professional machine. With my previous installations of R (2.10.1 32 bit was the most recent) the little icon that appeared in the title bar and in the taskbar at the bottom of windows was the R "R." Now however, the icon almost looks like a small windows Task Manager. I know this isn't ...

Calculating a Sample Covariance Matrix for Groups with plyr

I'm going to use the sample code from http://gettinggeneticsdone.blogspot.com/2009/11/split-apply-and-combine-in-r-using-plyr.html for this example. So, first, let's copy their example data: mydata=data.frame(X1=rnorm(30), X2=rnorm(30,5,2), SNP1=c(rep("AA",10), rep("Aa",10), rep("aa",10)), SNP2=c(rep("BB",10), rep("Bb",10), rep("bb",10...

How to include multiple tables programmaticaly into a Sweave document using R

Hello, I want to have a sweave document that will include a variable number of tables in. I thought the example below would work, but it doesn't. I want to loop over the list foo and print each element as it's own table. % \documentclass[a4paper]{article} \usepackage[OT1]{fontenc} \usepackage{longtable} \usepackage{geometry} \usepac...

Specifying column names from a list in the data.frame command.

I have a list called cols with column names in it: cols <- c('Column1','Column2','Column3') I'd like to reproduce this command, but with a call to the list: data.frame(Column1=rnorm(10)) Here's what happens when I try it: > data.frame(cols[1]=rnorm(10)) Error: unexpected '=' in "data.frame(I(cols[1])=" The same thing happens if I ...

R substitute on expression with assignment

Why do these two cases behave differently? >substitute(c1<-100,list(c1=100)) 100 <- 100 vs > substitute(c1=100,list(c1=100)) [1] 100 ...

Why the field separator character must be only one byte?

data <- read.delim("C:\\test.txt", header = FALSE, sep = "$$$$$") Error in scan(file, what = "", sep = sep, quote = quote, nlines = 1, quiet = TRUE, : invalid 'sep' value: must be one byte Why there is a restriction like this? Can I overcome it? ...

Reading correctly (alpha)numeric fields into R

A tab-delimited text file, which is actually an export (using bcp) of a database table, is of that form (first 5 columns): 102 1 01 e113c 3224.96 12 102 1 01 e185 101127.25 12 102 2 01 e185 176417.90 12 102A 3 01 e185 26261.03 12 I tried to import it in R with a command like data <- read.delim(...

[R] select values from list using Date as index

Suppose I have a list as follows bar=c() bar["1997-10-14"]=1 bar["2001-10-14"]=2 bar["2007-10-14"]=1 How can I select from this list all values for which the index is within a specific date range? So, if I look for all values between "1995-01-01" and "2000-06-01", I should get 1. And similarly for the period "2001-09-01" and "2007-11...

how can a test script inform R CMD check that it should emit a NOTE?

I'm writing a R library together with other developers. we are using RUnit for unit testing. our process for describing new functionality: we define new unit tests, initially marked as DEACTIVATED; one block of tests at a time we activate them and implement the function described by the tests. almost all the time we have a small amou...

Is there an RUnit checkException for warning()?

checkException will validate if meeting a stop() call, but not a warning() call. Is there a workaround or hack to check for warnings? (and make them silent during testing) thanks ...

improve my code for collapsing a list of data.frames

Dear StackOverFlowers (flowers in short), I have a list of data.frames (walk.sample) that I would like to collapse into a single (giant) data.frame. While collapsing, I would like to mark (adding another column) which rows have came from which element of the list. This is what I've got so far. This is the data.frame that needs to be co...

How can I determine if a function generates a graph

Is there a way to determine if a function generates a figure in R? For example, if we have functions f and g f = function(x,y){plot(x,y)} g = function(x,y){mean(x*y)} I would like able to run createFigure(f(x,y))#Returns TRUE createFigure(g(x,y))#Returns FALSE Thanks ...

R: ggplot2, how to get the parameters from a plotted linear model smoother?

I have a data.frame with 3 time series in it, shown below. When I plot them with a smoother time series, I want to be able to get the parameters of the linear model that I plot, but I can't see how to do that? > data day od series_id 1 1 0.10 A1 2 3 1.00 A1 3 5 0.50 A1 4 7 0.7...

Is there a weighted.median() function for R?

I'm looking for something similar in form to weighted.mean(). Sorry for posting such a banal question... new to R. I've found some solutions via search that write out the entire function but would appreciate something a bit more user friendly. ...

Command history in R

Is there any IDE -from the ones supporting R-, that gives access to the command history (at least to the current session's commands)? Or is there a way to get a (character or expression) vector with those commands in R? For those of you that have been using MATLAB, I mean something like the Command History window there.. Thank you ...

R single layer perceptron with nnet

I'm trying to create a single layer perceptron. If I use the nnet function to create a n-0-1 network (n being the number of inputs), is that equivalent to a perceptron? ...

Creating a Large Matrix in ff

I am trying to create a huge matrix in ff, and I know that ff is good for this sort of thing. But, there is a major problem. The dimensions of the matrix exceed .Machine$max_integer! I am running on a 64 bit machine, using 64bit R and 64bit ff. Is there any way to get around this problem? It's been suggested that R is using the MAX...