r

How can I background the R process in ESS / Emacs?

I often run long R scripts when I start my R environment. I would like to be able to load / run the R script in Emacs / ESS and continue other work in another buffer. When I press C-g or C-c C-c the process is interrupted, and I must restart the script. What is the best way to background the R process in ESS / Emacs? EDIT: Thank you ...

Is there any library in R to work with graphs (find shortest path and so on)?

Hi! I know that R is statistical pkg, but probably there is library to work with graphs and find shortest path btw 2 nodes. PS actually, I've found igraph and e1071, which one is better? Thank you ...

from ggplot2 to OOo workflow?

This is not really a programming question, but I try here none the less. I once used latex for my reports. But the people I work with needs to make small edits and do not have latex skillz. Openoffice is then the way to go. But saving ggplot images with dpi >100 makes for really ugly graphs. dpi = 600 is a no go (e.g. huge legend). So w...

R + Bioconductor : combining probesets in an ExpressionSet

Hi, First off, this may be the wrong Forum for this question, as it's pretty darn R+Bioconductor specific. Here's what I have: library('GEOquery') GDS = getGEO('GDS785') cd4T = GDS2eSet(GDS) cd4T <- cd4T[!fData(cd4T)$symbol == "",] Now cd4T is an ExpressionSet object which wraps a big matrix with 19794 rows (probesets) and 15 columns...

Last Observation Carried Forward In a data frame?

Hi all, I wish to implement a "Last Observation Carried Forward" for a data set I am working on which has missing values at the end of it. Here is a simple code to do it (question after it): LOCF <- function(x) { # Last Observation Carried Forward (for a left to right series) LOCF <- max(which(!is.na(x))) # the location of the...

program R- in ggplot restrict y to be >0 in LOESS plot

Here's my code: qplot(data=sites, x, y, main="Site 349") (p <- qplot(data = sites, x, y, xlab = "", ylab = "")) (p1 <- p + geom_smooth(method = "loess",span=0.5, size = 1.5)) p1 + theme_bw() + opts(title = "Site 349") Some of the LOESS lines and confidence intervals go below zero, but I would like to restrict the graphics to 0 and po...

How to do an alphanumeric sort in R

Is there an alphanumeric sort for R? Say I had a character vector like so: > seq.names <- c('abc21', 'abc2', 'abc1', 'abc01', 'abc4', 'abc201', '1b', '1a') I'd like to sort it aphanumerically, so I get back this: c('1a', '1b', 'abc1', 'abc01', 'abc2', 'abc4', 'abc21', 'abc201') Does this exist somewhere, or should I start coding? ...

Efficiently adding or removing elements to a vector or list in R?

I'm implementing an algorithm that involves lots of adding and removing things from sets. In R, this is slow because as far as I know, adding or removing things from a vector is slow, since the entire vector has to be re-allocated. Is there a way do do it more efficiently? Edit: My current solution is to use a boolean vector of the same...

Using reshape + cast to aggregate over multiple columns

In R, I have a data frame with columns for Seat (factor), Party (factor) and Votes (numeric). I want to create a summary data frame with columns for Seat, Winning party, and Vote share. For example, from the data frame df <- data.frame(party=rep(c('Lab','C','LD'),times=4), votes=c(1,12,2,11,3,10,4,9,5,8,6,15), ...

Getting caught in loops - R

I am looking at whether or not certain 'systems' for betting really do work as claimed, namely, that they have a positive expectation. One such system is based on the rebate on loss. You basically have a large master pot, say $1 million. Your bankroll for each game is $50k. The way it works, is as follows: 1) Start with $50k, always bet...

R: How can I reorder the rows of a matrix, data.frame or vector according to another one.

test1 <- as.matrix(c(1, 2, 3, 4, 5)) row.names(test1) <- c("a", "d", "c", "b", "e") test2 <- as.matrix(c(6, 7, 8, 9, 10)) row.names(test2) <- c("e", "d", "c", "b", "a") test1 [,1] a 1 d 2 c 3 b 4 e 5 test2 [,1] e 6 d 7 c 8 b 9 a 10 How can I reorder test2 so that the rows are in the same order a...

Matrix multiplication in java (RE-POST)

Apologies for the re-post; the earlier time I'd posted I did not have all the details. My colleague, who quit the firm was a C# programmer, was forced to write Java code that involved (large, dense) matrix multiplication. He's coded his own DataTable class in Java, in order to be able to a) create indexes to sort and join with other D...

Comparing values longitudinally in R... with a twist

I have the results of a test taken by a number of individuals at as many as four time periods. Here's a sample: dat <- structure(list(Participant_ID = c("A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C", "C"), phase = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("base", "sixmos", "twelvemos", "eighteen...

Need helping creating a loop in R. Have many similarly named variables I have to apply the same functions to. Thanks!

I am using a dataset w/variables that have very similar names. I have to apply the same functions to 13 variables at a time and I'm trying to shorten the code, instead of doing each variable individually. q01a.F=factor(q01a) q01b.F=factor(q01b) q01c.F=factor(q01c) q01d.F=factor(q01d) q01e.F=factor(q01e) q01f.F=factor(q01f) q01g.F=factor...

R plot- SGAM plot counts vs. time - how do I get dates on the x-axis?

I'd like to plot this vs. time, with the actual dates (years actually, 1997,1998...2010). The dates are in a raw format, ala SAS, days since 1960 (hence as.date conversion). If I convert the dates using as.date to variable x, and do the GAM plot, I get an error. It works fine with the raw day numbers. But I want the plot to display t...

Can't get multiple panel plots with chartSeries function from quantod package in R

Jeff Ryan's quantmod package is an excellent contribution to the R finance world. I like to use chartSeries() function, but when I try to get it to display multiple panes simultaneously, it doesn't work. par(mfrow=c(2,2)) chartSeries (SPX) chartSeries (SPX, subset="2010") chartSeries (NDX) chartSeries (NDX, subset="2010") would nor...

R dates "origin" must be supplied

axis.Date(1,sites$date, origin="1960-10-01") Error in as.Date.numeric(x) : 'origin' must be supplied Why is it asking me for the origin when I supplied it in the above code? ...

Automating R Script

I have written an R script that pulls some data from a database, performs several operations on it and post the output to a new database. I would like this script to run every day at a specific time but I can not find any way to do this effectively. Can anyone recommend a resource I could look at to solve this issue? I am running thi...

R question. Using lappy on a data.frame and creating new variables w/ output.

Hello, I have 13 quantitative variables in a data.frame (called 'UNCA'). The variables are named q01_a, q01_b, ...q01_m. I want to create 13 new variables that have the same values but are coded as a factor. I would like to name these 13 new variables q01_a.F, q01_b.F, ...q01_m.F. Any help would be greatly appreciated! ...

Replace Loops in R function

Hi, I'm new to R, and I'm having trouble figuring out how to replace the FOR loop in the function below. The function estimates a population mean. Any help at all would be much appreciated. Thank you! myFunc<- function(){ myFRAME <- read.csv(file="2008short.csv",head=TRUE,sep=",") meanTotal <- 0 for(i in 1:100) { mySample <- sampl...