r

Calculate within and between variances and confidence intervals in R

Hello, I need to calculate the within and between run variances from some data as part of developing a new analytical chemistry method. I also need confidence intervals from this data using the R language I assume I need to use anova or something ? My data is like > variance Run Rep Value 1 1 1 9.85 2 1 2 9.95 3 1 ...

Painless way to install a new version of R?

Andrew Gelman recently lamented the lack of an easy upgrade process for R (probably more relevant on Windows that Linux). Does anyone have a good trick for doing the upgrade, from installing the software to copying all the settings/packages over? This suggestion was contained in the comments and is what I've been using recently. First...

MS-SQL Bulk Insert w/ RODBC

Is it possible to perform a bulk insert into an MS-SQL Server (2000, 2005, 2008) using the RODBC package? I know that I can do this using freebcp, but I curious if the RODBC package implements this portion of the Microsoft SQL API and if not, how difficult it would be to implement it. -- Dan ...

Choose variables based on name (simple regular expression)

I would like to incorporate variable names that imply what I should do with them. I imagine a dataframe "survey". library(Rlab) # Needed for rbern() function. survey <- data.frame(cbind( id = seq(1:10), likert_this = sample(seq(1:7),10, replace=T), likert_that = sample(seq(1:7), 10, replace=T), dim_bern_varx = rbern(10, 0.6), ...

Real time data exchange between R and Windows application

I am using R for scatter plots, and now also for 3D cloud plots on top of a image. I have an application that generates a lot of such 3D coordinates and I need to see those coordinates on top of the image at run-time (for debugging purposes). My question, Is it possible for my Windows application to communicate to R at run-time. ...

What's the best trick to speed up a monte carlo simulation?

Whenever I run large scale monte carlo simulations in S-Plus, I always end up growing a beard while I wait for it to complete. What are the best tricks for running monte carlo simulations in R? Any good examples of running processes in a distributed fashion? ...

How to assign output of cat to an object?

How would it be possible in the example below to skip the step of writing to file "test.txt", i.e. assign the cat-result to an object, and still achieve the same end result? I thought I'd include the full example to give background to my problem. test <- c("V 1", "x", "1 2 3", "y", "3 5 8", "V 2", "x", "y", "V 3", "y", "7 2 1", "V 4", ...

Plotting a wireframe AND a cloud with lattice in R

I have a nice surface that represents nonlinear multi-part regression results on a regression with two independent variables. I would like to plot the regression predicted values as a nice 3D surface and then show the actual values as point that bounce around the surface. This would be the 3D version of plotting a regression line and sho...

Relief from backslash irritation in R for Windows

Early in my R life I discovered the pain of R and windows being on different pages when it came to the separator between directories and subdirectories. Eventhough I know about the problem, I am still pained by manually having to put a backslash in front of all my backslashes or replacing all of them with forward slashes. I love copyin...

for each group summarise means for all variables in dataframe (ddply? split?)

A week ago I would have done this manually: subset dataframe by group to new dataframes. For each dataframe compute means for each variables, then rbind. very cluncky ... Now i have learned about split and plyr, and I guess there must be an easier way using these tools. Please don't prove me wrong. test_data <- data.frame(cbind( var0...

Reading text files using read.table in R

I have a text file with an "id" and "name" column, and I'm trying to read it into a data frame in R: d = read.table("foobar.txt", sep="\t") But for some reason, a lot of lines get merged -- e.g., in row 500 of my data frame, I'll see something like row 500: 500 Bob\n501\tChris\n502\tGrace [So if my original text file has, say, 5000 li...

How can I produce report quality tables from r ?

If I have the following dataframe called result > result Name CV LCB UCB 1 within 2.768443 1.869964 5.303702 2 between 4.733483 2.123816 18.551051 3 total 5.483625 3.590745 18.772389 > dput(result,"") structure(list(Name = structure(c("within", "between", "total" ), .rk.invalid.fields = list(), .Label = charac...

Connecting GNU R to PostgreSQL

Hello friendly Overflowers, I have GNU R installed (the S-like statistics package; version 2.8.1) and PostgreSQL (8.4.1) but I cannot connect GNU R to my RDBMS. When I first did this (years ago - code lost) DBI for R didn't exist. Now it does. I am also confused as to which R package to use. A quick search returns: - RPostgreSQL seems...

How do I make (ugh) bull's-eye charts in R?

A colleague of mine needs to plot 101 bull's-eye charts. This is not her idea. Rather than have her slave away in Excel or God knows what making these things, I offered to do them in R; mapping a bar plot to polar coordinates to make a bull's-eye is a breeze in ggplot2. I'm running into a problem, however: the data is already aggregat...

Unit of Analysis Conversion, weird problem

Before I start I'd like to say that this may not be the appropriate medium for such a question, so if I am out of place, please tell me. I do statistical work for an off shoot of a land grant University and have been presented with a problem that I think may be too complicated to solve. Hopefully you can validate me. We are working on...

Getting the state of variables after an error occurs in R

Let's say I have just called a function, f, and an error occurred somewhere in the function. I just want to be able to check out the values of different variables right before the error occurred. Suppose my gut tells me it's a small bug, so I'm too lazy to use debug(f) and too lazy to insert browser() into the part of the function wh...

pmax (parallel maximum) eqivualent for rank in R

If one has 4 judges and they each give a score for a particular performer or a particular topic then one could have 4 vectors with each containing the score. But one would like to turn that into a rank to overcome grade inflation by one judge compared to another. that is easy transform(assignment,judge1.rank=rank(judge1),judge2.rank=ran...

How do you write a CSV in R with the matrix names (dimnames(M)) intact in R?

Is there a command in R that will allow you to write a CSV file that has the row and column names of a matrix (dimnames(M))? Whenever I output the file, the names are gone. help(write) doesn't mention that this is possible to do. ...

Emacs ESS: Eval region vs. source()

I love the Emacs ESS combination. I love sending lines, functions, regions, and buffers of code to the command line for evaluation without using the mouse. However, I've noticed that the Eval Function command in Emacs is much slower than simply running source("fns.R"), where fns.R is the file that contains the function I want to eval...

How to source file.R without output

Is it possible to source a file without printing all the charts etc (already tried with echo=F)? In my case I call the png("filename%03d.png") device early in the script. It is not to big a hassle to comment this out - but all the charts do take a lot of time to render. (the specific file I am working with now uses base-graphics - but ...