r

Help me copy data over the Amazon's EC2 and run a script.

I am a novice as far as using cloud computing but I get the concept and am pretty good at following instructions. I'd like to do some simulations on my data and each step takes several minutes. Given the hierarchy in my data, it takes several hours for each set. I'd like to speed this up by running it on Amazon's EC2 cloud. After readin...

How to use R's ellipsis feature when writing your own function?

The R language has a nifty feature for defining functions that can take a variable number of arguments. For example, the function data.frame takes any number of arguments, and each argument becomes the data for a column in the resulting data table. Example usage: > data.frame(letters=c("a", "b", "c"), numbers=c(1,2,3), notes=c("do", "re...

R: building a simple command line plotting tool/Capturing window close events

I am trying to use R within a script that will act as a simple command line plot tool. I.e. user pipes in a csv file and they get a plot. I can get to R fine and get the plot to display through various temp file machinations, but I have hit a roadblock. I cannot figure out how to get R to keep running until the users closes the window....

R table column order when including the empty string

I have a series of value that include the empty string levels(mydata$phone_partner_products) "" "dont_know" "maybe_interesting" "not_interesting" "very_interesting" "very_not_interesting" If I make a frequencies table I get this table(mydata$phone_partner_products) ...

Best programming language for teaching econometrics?

I will be teaching an econometrics course to masters students in the fall. I think it is important for them to learn programming with data as an essential applied research skill. What suggestions do you have for the programming language. I am leaning mostly towards R. What others should I consider? ...

LAbeling with Percentage in R plot

Hi I have made this function that takes a table and prepare the label for a barplot prepare_labels <- function(ft){ labs <- ft labs <- paste(labs, "\n", sep="") labs <- paste(labs, round(prop.table(ft)*100,2), sep="") labs <- paste(labs, "%", sep="") return(labs) } It actually works fine, but is there any better way to write...

R: dev.copy2pdf, multiple graphic devices to a single file, how to append to file?

Hi everybody, I have a script that makes barplots, and opens a new window when 6 barplots have been written to the screen and keeps opening new graphic devices whenever necessary. Depending on the input, this leaves me with a potential large number of openened windows (graphic devices) which I would like to write to a single PDF file. ...

IN R counting hierarchical data

I have a list of counties in each state that received nonattainment status in years 1995-2005. I want to know how many counties in each state each year that received this status. If my data is formatted like this, State1 Country1 YR1 Yr2 Yr3 Yr4... State1 Country2 YR1 Yr2 Yr3 Yr4 State2 County1 Yr1 Yr2..... Each year variable coul...

Add a variable to a data frame containing max value of each row

I want to add a variable (column) to a dataframe, containing in each row the max value of that row across 2nd to 26th column. For the first row, the code would be: df$max[1] <- max(df[1,2:26]) I am looking for a way to generalize that for rows 1 to 865. If I give df$max[1:865] <- max(df[1:865, 2:26]) I get the overall max across all...

R: How to get a stack trace from the snow package

How can I get a stack trace back from a snow node after an error occurs? I'm getting errors when I use parSapply that do not occur when I use sapply. Snow is nice enough to give me the error message but it would be much more useful for me to have the kind of stack trace you can get from traceback(). So far I have tried: options(showWarn...

Root mean square deviation on binned GAM results using R

Background A PostgreSQL database uses PL/R to call R functions. An R call to calculate Spearman's correlation looks as follows: cor( rank(x), rank(y) ) Also in R, a naïve calculation of a fitted generalized additive model (GAM): data.frame( x, fitted( gam( y ~ s(x) ) ) ) Here x represents the years from 1900 to 2009 and y is the a...

R error promise already under evaluation when using subset in function but no error in script

I'm getting a strange error when I run the following function: TypeIDs=c(18283,18284,17119,17121,17123,17125,17127,17129,17131,17133,18367,18369,18371,18373,18375,18377,18379) featsave<-function(featfile,TypeIDs=TypeIDs) { mydata1<-read.table(featfile,header=TRUE) mydata2<-subset(mydata1,TypeID %in% TypeIDs) mydata<-as.dat...

Undo command in R

I can't find something to the effect of an undo command in R (neither on An Introduction to R nor in R in a Nutshell). I am particularly interested in undoing/deleting when dealing with interactive graphs. What approaches do you suggest? Thanks, Roberto ...

Logistic Regression Using Zelig [R]

I'm running a logit model using the zelig package in R: z.out <- zelig(trade961a ~ age962 + education962 + personal962 + economy962 + partisan962 + employment962 + union962 + home962 + market962 + race962 + income962, data=data96, model="logit") The dependent variable, trade961a, is a dichotomous factor variable. All other variables a...

ggplot custom colors palette

Does anyone knows how to define a custom palette to be used in ggplot when geom="bar". I have an array of colors I would like to use: > rhg_cols [1] "#771C19" "#AA3929" "#E25033" "#F27314" "#F8A31B" "#E2C59F" "#B6C5CC" [8] "#8E9CA3" "#556670" "#000000" But When I try to pass it to nothing happened ggplot(mydata, aes(factor(phone_...

define $ right parameter with a variable in R

I would like to pass a variable to the binary operator $. Let's say I have this > levels(diamonds$cut) [1] "Fair" "Good" "Very Good" "Premium" "Ideal" Then I want to make a function that takes as parameter the selector for $ my_helper <- function (my_param) { levels(diamonds$my_param) } But this doesn't work > my_h...

What techniques exists in R to visualize a "distance matrix" ?

Hi all, I wish to present a distance matrix in an article I am writing, and I am looking for good visualization for it. So far I came across balloon plots (I used it here, but I don't think it will work in this case), heatmaps (here is a nice example, but they don't allow to present the numbers in the table, correct me if I am wrong. ...

Equivalent of matlab 'ans' in R

In matlab, you can re-use the result of the (non affected) preceding calculous: it is stored in variable ans. Does R has something equivalent ? ...

R time series object with two time dimensions

When you study time series forecast you most often have to deal with two times: the time you issue your forecast and the time you make your forecast for. These two times are not regularly sampled in general. What R object do you suggest to deal with these two times ? please indicate advantages and drawback. If no object exist, how sho...

how to perform Array Indexing in R Language

hey ppl, i am new to r language.. so i just want to know how array indexing is done in r language , i mean like sorting or any calcultaions that involve 2-d arrays. ...