r

Tool to diagonalize large matrices

I want to compute a diffusion kernel, which involves taking exp(b*A) where A is a large matrix. In order to play with values of b, I'd like to diagonalize A (so that exp(A) runs quickly). My matrix is about 25k x 25k, but is very sparse - only about 60k values are non-zero. Matlab's "eigs" function runs of out memory, as does octave's ...

taking care of dependencies in your functions

How do you solve the dependencies of packages within your functions? I add require(package) into the function, but I wonder if there's a preferred way of accomplishing this task. ...

How do I sub sample data by group using ddply?

I've got a data frame with far too many rows to be able to do a spatial correlogram. Instead, I want to grab 40 rows for each species and run my correlogram on that subset. I wrote a function to subset a data frame as follows: samp <- function(dataf) { dataf[sample(1:dim(dataf)[1], size=40, replace=FALSE),] } Now I want to ap...

How to use egarch on a ts (in OSX)

stock.ba is a ts object of monthly stock returns and I would like to fit an eGARCH model, but I keep getting this error using a new download of rgarch in R 2.10.1: > stock.ba.egarch <- ugarchfit(stock.ba, spec) Error in UseMethod("ugarchfit") : no applicable method for 'ugarchfit' applied to an object of class "ts" Here's the (rele...

[R] how do I quickly group the time column in a dataframe into intervals?

Hi, Assuming in R, I have a data.frame with the first column representing the time (as POSIXct). The rest of the columns (e.g., columns 2) are numeric data. I would like to group time into 3-minute intervals. Each interval will the the average of values that falls into that particular interval. Right now, I have a for-loop that iterat...

Why does R sometimes stop displaying output?

Sometimes R stops displaying output. I type the number 1, followed by the return key, and nothing appears. This situation occurred after I pressed the "STOP" icon in the window, which is for stopping long calculations. I'm using R 2.11.0 on a Mac. Does pressing "STOP" cause R to stop displaying output? How do I get R to display output ...

How to indent a buffer in ESS?

ESS allows us to indent a line and an expression. Is there a key binding for indenting a buffer? If not, can we create it? ...

Non-linear regression models in PostgreSQL using R

Background I have climate data (temperature, precipitation, snow depth) for all of Canada between 1900 and 2009. I have written a basic website and the simplest page allows users to choose category and city. They then get back a very simple report (without the parameters and calculations section): The primary purpose of the web appli...

how to save a fitted R model for later use

Sorry for this novice question: if I fit a lm() model or loess() model, and save the model somewhere in a file or in database, for later using by third party with predict() method, do I have to save the entire model object? Since returned model object contains orginal raw data, this returned object can be huge. ...

which time series class to use in R for financial data?

for working with financial time series, like daily stock prices or intraday data, which time series packages are preferred? xts, plain zoo, or timeSeries or something else? I use both xts and zoo, but sometimes not sure to use xts exclusively or sometimes zoo have advantage of lighter overhead; also, I remembered a review paper on all th...

Loading, listing, and using R Modules and Functions in PL/R

I am having difficulty with: Listing the R packages and functions available to PostgreSQL. Installing a package (such as Kendall) for use with PL/R Calling an R function within PostgreSQL Listing Available R Packages Q.1. How do you find out what R modules have been loaded? SELECT * FROM r_typenames(); That shows the types that a...

Homoscedascity test for Two-Way ANOVA

I've been using var.test and bartlett.test to check basic ANOVA assumptions, among others, homoscedascity (homogeniety, equality of variances). Procedure is quite simple for One-Way ANOVA: bartlett.test(x ~ g) # where x is numeric, and g is a factor var.test(x ~ g) But, for 2x2 tables, i.e. Two-Way ANOVA's, I want to do something lik...

Using recode in R

I'm trying to use recode in R (from the car package) and it is not working. I read in data from a .csv file into a data frame called results. Then, I replace the values in the column Built_year, according to the following logic. recode(results$Built_year, "2 ='1950s';3='1960s';4='1970s';5='1980s';6='1990s';7='2000 or later'") When I c...

large amount of data in many text files - how to process?

Hi, I have large amounts of data (a few terabytes) and accumulating... They are contained in many tab-delimited flat text files (each about 30MB). Most of the task involves reading the data and aggregating (summing/averaging + additional transformations) over observations/rows based on a series of predicate statements, and then saving th...

ESS/AucTeX/Sweave integration

I'm using GNU/Linux distro (Arch, if that's relevant), Emacs v23.2.1, ESS v5.9 and AucTeX v11.86. I want to setup AucTeX to recognize .Rnw files, so I can run LaTeX on .Rnw files with C-c C-c and get .dvi file automatically. I reckon it's quite manageable by editing .emacs file, but I still haven't got a firm grasp on Elisp. Yet anoth...

Make PDF help files open automatically

In R, if we set the help_type argument of help() function to 'html' and call it, it will automatically open the html help in a browser. However, this is not the case for help_type = 'pdf'. Only the pdf is generated. How can I make it automatically after the help file is generated? I believe that pdf help are preferred by some as it can d...

Pass variable name to a function in r

Is it possible to pass just a variable name in a function call and have it utilised as such within the function?? pseudocode: q<-function(A){ b<-(w%in%A.2|w%in%A.7) factor(b,levels=c(F,T),labels=c("non-"A,A))} w<-c(0:10) e.2<-c(1,2) e.7<-c(6,7) what I´d like to do is q(e) and have returned non-e,e,e,non-e,non-e,e,e,...

How do I plot more than one series using qplot?

I'm trying to understand how to have more than one series on a plot, using the following data. Year <- c('1950', '1960', '1970', '1980') Bus <- c(10,20,30,40) Bus.sd <- c(1.1, 2.2, 3.3, 4.4) Car <- c(20, 20, 40, 40) Car.sd <- c(1.1, 2.2, 3.3, 4.4) sample_data = data.frame(Year, Bus, Bus.sd, Car, Car.sd) qplot(Year, Bus, data=sample_da...

R multi plot log-log Label Problem

I'm trying to make a graph of a table and graph it in log space. First of all, plot(dat) gives me the grid of graphs Second of all, plot(dat, log="xy") gives me the correct plots of data in log space However, plot(dat, log="xy") ruins the main diagonal's labels of names(dat) R version 2.11.0 Sample Data: cold cold_contro...

R: how to make a unique set of names from a vector of strings?

Hi, I have a vector of strings. Check out my vector, it's awesome: > awesome [1] "a" "b" "c" "d" "d" "e" "f" "f" I'd like to make a new vector that is the same length as awesome but where, if necessary, the strings have been uniqueified. For example, a valid output of my desired function would be > awesome.uniqueified [1] "a" "b" "c...