r

Dealing with timestamps in R

I have multiple lists of measurements. In each list have the timestramp formated as a string ("2009-12-24 21:00:07.0") and I know that each measurement in the list is separated by 5 seconds. I want to combine all data into a huge data.frame in R. Afterwards I want to be able to easily access the time difference of two measurements so I p...

maximum plot points in R?

Hello, I have come across a number of situations where I want to plot more points than I really ought to be -- the main holdup is that when I share my plots with people or embed them in papers, they occupy too much space. It's very straightforward to randomly sample rows in a dataframe. if I want a truly random sample for a point plot...

Grid in an R plot

Is there a command to easily add a grid onto an R plot? ...

Efficiency of operations on R data structures

Hi, I'm wondering if there's any documentation about the efficiency of operations in R, specifically those related to data manipulation. For example, I imagine it's efficient to add columns to a data frame, 'cause I'm guessing you're just adding an element to a linked-list. I imagine adding rows is slower because (I guess) vectors are h...

Generating a lagged time series cross sectional variable in R

Hello - I am a new R user. I have a time series cross sectional dataset and, although I have found ways to lag time series data in R, I have not found a way to create lagged time-series cross sectional variables so that I can use them in my analysis. Thank you for your help. ...

R accessing DB query results by column and row number

Hi, I am new to R language. I have successfully loaded a query's resultset into a variable. Now I want to access the resultset data by column name and row number. And I need to verify if it is Null (it is shown as < NA > in result) then send a mail by bat file with php. My sample code is below. library(RODBC) newconn = odbcConnect("db...

Memory Usage in Foreach Function

I was wondering if there is any way to get the foreach package in R to use a pre-allocated structure to put results. basically it involves lots of small linalg operations on very big data sets. My non-foreach original code is something like results <- rep(NA,m*l*[big.number]) dim(results) <- c(m,l,[big.number]) for (i in 1:m){ for ...

Optimising R function that adds a new column to a data.frame

I have a function that at the moment programmed in a functional model and either want to speed it up and maybe solve the problem more in the spirit of R. I have a data.frame and want to add a column based on information that's where every entry depends on two rows. At the moment it looks like the following: faultFinging <- function(hear...

Printing stack trace and continuing after error occurs in R

I'm writing some R code that calls other code that may fail. If it does, I want to print a stack trace (to track down what went wrong), then carry on regardless. However, the traceback() function only provides information about uncaught exceptions. I can get the result I want via a rather complex, natty construction involving tryCatch an...

mca or various ca (multivariate analysis)

Hello. I will make a analysis about some information of my company. I thought making a ca to representate the association between two variables. I have 3 variables: Category, Tag, Valoration. My idea is to make 2 analysis, one to view the association between Category - Valorarion and a second analysis between Tag - Valoration. But I th...

Data manipulation with R: Restructuring Data

I have a dataset that looks like this: a <- data.frame(rep(1,5),1:5,1:5) b <- data.frame(rep(2,5),1:5,1:5) colnames(a) <- c(1,2,3) colnames(b) <- c(1,2,3) c <- rbind(a,b) 1 2 3 1 1 1 1 2 1 2 2 3 1 3 3 4 1 4 4 5 1 5 5 6 2 1 1 7 2 2 2 8 2 3 3 9 2 4 4 10 2 5 5 but I want it to be restructured to this: 2_1 2_2 3_1 3_2 ...

Tutorial for R vectorised programming

Can someone point me to a good tutorial for using vectorized programming methods in R. At the moment it feels very magical to me and I don't really understand what R's doing. Especially with regards to if statements and addressing values neighboring rows. ...

number of months between two dates?

Hi, Is there a standard/common method/formula to calculate the number of months between two dates in R? I am looking for something that is similar to http://www.mathworks.com/access/helpdesk/help/toolbox/finance/months.html Thanks. ...

Rscript: Define path file as argument

I try this command : Rscript "/Users/test/Scripts/arg_test.R" "path_in=/Users/test/GR/web-app/Rproject/Inputs/Rmerge/Description.csv" path_in2="/Users/test/IdeaProjects/Rproject/Inputs/Rmerge/Template_Auto.csv" but I have this error : Error in parse(text = args[[i]]) : unexpected '/' in "path_in=/" Part of Rscript : args=(commandArg...

where do I find the definition of class objects in spatstat

I would like to know what kind of information does an object of class Spatialpolygons has versus an object of class Polygons. ...

Fastest numerical solution of a real cubic polynomial?

R question: Looking for the fastest way to NUMERICALLY solve a bunch of arbitrary cubics known to have real coeffs and three real roots. The polyroot function in R is reported to use Jenkins-Traub's algorithm 419 for complex polynomials, but for real polynomials the authors refer to their earlier work. What are the faster options for a r...

R Language: Import multiline SQL query to single string

In R, how can I import the contents of a multiline text file (containing SQL) to a single string? The sql.txt file looks like this: SELECT TOP 100 setpoint, tph FROM rates I need to import that text file into an R string such that it looks like this: > sqlString [1] "SELECT TOP 100 setpoint, tph FROM rates" That's so that I ...

Can I do margin calculations in ddply()?

The cast() function is great at calculating margins for aggregate values: cast(df, IDx1+IDx2~IDy1, margins=c('IDx1','IDx2','grand_row'),c(min, mean, max)) The problem is that I need to weight my means using a second vector and a custom function. Of course, ddply() lets me apply custom aggregation functions to my grouped records: ddp...

Calling R from S-Plus?

Does anyone have any suggestions for a good way to call R from S-Plus? Ideally I would like to just pass code to R and get data back without having to write anything too elaborate to integrate them. I should add that I'm familiar with the RinS package on Omegahat, but I haven't used it. I was under the impression that Insightful had...

What is the equivalent of var_dump() in r?

I'm looking for a function to dump variables and objects, with human readable explanations of their data types. For instance, in php var_dump does this. $foo = array(); $foo[] = 1; $foo['moo'] = 2; var_dump($foo); Yields: array(2) { [0]=> int(1) ["moo"]=> int(2) } ...