r

BIC of lmrob model (robustbase)?

Is there a way to extract a BIC (Bayesian information criterion) from a robust regression model, say "lmrob" from the "robustbase" package? ...

Storing R Objects in a relational database

I frequently create nonparametric statistics (loess, kernel densities, etc) on data I pull out of a relational database. To make data management easier I would like to store R output back inside my DB. This is easy with simple data frames of numbers or text, but I have not figured out how to store R objects back in my relational database...

How do you convert dates/times from one time zone to another in R?

If I have a date like this in London time: "2009-06-03 19:30", how can I convert it to the equivalent time in the US West Coast? ...

Re-generate same simulated data set in a MC simulation study

Suppose I simulate a data set using set.seed(1234); rnorm(100). Later, I would like to find the 90th data value simulated without re-simulating the whole data set. How can this be done? Does .Random.seed play a role? While this may seem to be an overly simplified problem (especially when one could just run the whole code again), this ...

Is there a systematic way to convert R code with loops to vectorized code?

Most looping code looks like this retVal=NULL for i { for j { result <- *some function of vector[i] and vector[j]* retVal = rbind(retVal,result) } } Since this is so common, is there a systematic way of translating this idiom? Can this be extended to most loops? ...

Best way to plot interaction effects from a linear model

Hi All, In an effort to help populate the R tag here, I am posting a few questions I have often received from students. I have developed my own answers to these over the years, but perhaps there are better ways floating around that I don't know about. The question: I just ran a regression with continuous y and x but factor f (where le...

How to make an R function return multiple columns and append them to a data frame?

Starting with this data frame myDF = structure(list(Value = c(-2, -1, 0, 1, 2)), .Names = "Value", row.names = c(NA, 5L), class = "data.frame") Suppose I want to run this function on every row of myDF$Value getNumberInfo <- function(x) { if(x %% 2 ==0) evenness = "Even" else evenness="Odd" if(x > 0) positivity = "Positive" else posi...

Analyzing Path Data

I have data representing the paths people take across a fixed set of points (discrete, e.g., nodes and edges). So far I have been using igraph. I haven't found a good way yet (in igraph or another package) to create "canonical" paths summarizing what significant sub-groups of respondents are doing. A canonical path can be operationali...

Making good column names R

I read a table from Microsoft Access using RODBC. Some of the variables had a name with a space in it. R has no problem with it but I do. I cannot find out how to specify the space names(alltime) [1] "ID" "LVL7" "Ref Pv No" "Ref Pv Name" "DOS" "Pt Last Name" "Pt First Name" "MRN" "CPT" ...

How to call R from within a web server (like Apache)?

That is, is there an embedded R interpreter available? ...

Best way to search for R packages?

Related question how to search for r materials Part of the reason why the R community has been attracted to a tag based service like StackOverflow---I think---is that information on R is fundamentally difficult to find online. Services like RSeek have made this slightly less painful, however, I often find the search results scatte...

Questions about missing data

In a matrix, if there is some missing data recorded as "NA", how could I delete rows with "NA" in the matrix? Can I use na.rm? ...

How to split a data frame by rows, and then process the blocks?

I have a data frame with several columns, one of which is a factor called "site". How can I split the data frame into blocks of rows each with a unique value of "site", and then process each block with a function? The data look like this: site year peak ALBEN 5 101529.6 ALBEN 10 117483.4 ALBEN 20 132960.9 ALBEN 50 153251.2 ALBEN 100 168...

New vector based on comparing elements of two other vectors "lagged"?

I have two vectors, "subject" and "target". I want to create a new vector based on comparisons between the two existing vectors, with elements being compared "lagged". I've solved this okay using the loop below, but I'm essentially wondering whether there's a more elegant solution using apply? subject <- c(200,195,190,185,185,185,188,18...

Increasing the memory available to R processes

I would like to increase the amount of memory available to R. What are the methods for achieving this? ...

Lazy evaluation of supplied arguments

Say I have the following function: foo <- function(x, y = min(m)) { m <- 1:10 x + y } When I run foo(1), the returned value is 2, as expected. However, I cannot run foo(1, y = max(m)) and receive 11, since lazy evaluation only works for default arguments. How can I supply an argument but have it evaluate lazily? ...

Calling Clojure from within R?

Is there any link between R and Clojure? I am aware of Incanter, but am ideally looking for an R package for Clojure or any future plans for one, in order to call clojure from within R. ...

Creating interactive pplets from R Output

Currently, I generate results from statistical analyses (e.g., a three dimensional plot) and then "manually" move it to processing - a graphics programming language) where I can (with some simple coding) export an interactive java applet (e.g., allow the person viewing the plot to move in, out and around the data points). Can I keep thi...

Determining memory usage?

I'd like to work out how much RAM is being used by each of my objects inside my current workspace. Is there an easy way to do this? ...

renaming the output column with the plyr package in R

Hadley turned me on to the plyr package and I find myself using it all the time to do 'group by' sort of stuff. But I find myself having to always rename the resulting columns since they default to V1, V2, etc. Here's an example: mydata<-data.frame(matrix(rnorm(144, mean=2, sd=2),72,2),c(rep("A",24),rep("B",24),rep("C",24))) colnames(...