Re: [R] Getting the index of specific quantiles

2016-11-22 Thread Matteo Richiardi
t; [1] 4 > > And here's one of the various ways to get the entire set: > >> xq <- quantile(x) >> sapply(xq, function(y)which.min(abs(x - y))) > 0% 25% 50% 75% 100% >347 1 8 > > Sarah > > On Tue, Nov 22, 2016 at 7:21 AM, Matteo Richiardi > <mat

[R] Getting the index of specific quantiles

2016-11-22 Thread Matteo Richiardi
Dear R-users, a very easy one for you, I guess. I need to extract the indexes of the elements corresponding to different quantiles of a vector. When a quantile is an interpolation between two adjacent values, I need the index of the value which is closer (the lower value - or the higher value for

[R] Dynamically populate a vector by iteratively applying a function to its previous element.

2016-05-27 Thread Matteo Richiardi
I want to dynamically populate a vector by iteratively applying a function to its previous element, without using a 'for' cycle. My solution, based on a question I posted some times ago for a more complicated problem (see "updating elements of a list of matrixes without 'for' cycles") was to

[R] updating elements of a list of matrixes without 'for' cycles

2016-01-29 Thread Matteo Richiardi
Hi, following an earlier suggestion from the list, I am storing my data in a "cube", i.e. an array of matrixes. Is there any smarter way of updating the elements of the cube through a function, other than the three 'for' cycles in the example below? (please note that the example is simplistic; in

[R] creating cubes

2016-01-15 Thread Matteo Richiardi
What is the best way to store data in a cube? That is, I need to create a data structure D with three indexes, say i,j,h, so that I can access each data point D[i,j,h], and visualise sections like D[i,j,] or D[,,h]. I have tried to create an array of matrixes: D <-matrix(matrix(NA,i,j),h) but

Re: [R] creating cubes

2016-01-15 Thread Matteo Richiardi
> > On Fri, Jan 15, 2016 at 2:20 PM, Matteo Richiardi > <matteo.richia...@gmail.com> wrote: >> >> What is the best way to store data in a cube? That is, I need to create a >> data structure D with three indexes, say i,j,h, so that I can access each >> data poi

Re: [R] assigning values to elements of matrixes

2015-12-24 Thread Matteo Richiardi
= get(paste("M_",s,sep="")) > M[i,j] = value > assign(paste("M_",s,sep=""),M, envir = .GlobalEnv) > } > > foo2("a",1,2,15) > > cheers > Peter > > > On 23 Dec 2015, at 09:44, Matteo Richiardi <matte

[R] assigning values to elements of matrixes

2015-12-23 Thread Matteo Richiardi
I am following the example I find on ?assign: a <- 1:4 assign("a[1]", 2) This appears to create a new variable named "a[1]" rather than changing the value of the vector. Am I missing something here? How can I assign a value to a specified element of a vector/matrix? Of course, my problem is

Re: [R] Applying a function to a matrix using indexes as arguments

2015-12-17 Thread Matteo Richiardi
semius <dwinsem...@comcast.net> > wrote: > > > > > >> On Dec 16, 2015, at 4:18 PM, Matteo Richiardi < > matteo.richia...@gmail.com> wrote: > >> > >> I have to evolve each element of a matrix W > >> > >> W <-

Re: [R] Applying a function to a matrix using indexes as arguments

2015-12-16 Thread Matteo Richiardi
ease excuse my brevity. > > On December 16, 2015 4:18:56 PM PST, Matteo Richiardi < > matteo.richia...@gmail.com> wrote: > >> I have to evolve each element of a matrix W >> >> W <- matrix(0,2,3) >> >> according to some function which uses the indic

[R] Applying a function to a matrix using indexes as arguments

2015-12-16 Thread Matteo Richiardi
I have to evolve each element of a matrix W W <- matrix(0,2,3) according to some function which uses the indices of the matrix [i,j] as arguments: w.fun = function(i,j) { return A[i]*B[j]/(C[i,j]) } where A<-c(100,100) B<-c(200,200,200) C <- matrix( rnorm(6,mean=0,sd=1), 2, 3) How can I do

Re: [R] Create a data.table by looping over variable names

2015-12-16 Thread Matteo Richiardi
Hi, thanks a lot to everybody for your help. Very nice suggestions! Matteo On 16 December 2015 at 12:53, Matteo Richiardi <matteo.richia...@gmail.com> wrote: > I apologise for this very basic question, but I found no answers on the > web. > I want to create a data.table with n co

[R] Create a data.table by looping over variable names

2015-12-16 Thread Matteo Richiardi
I apologise for this very basic question, but I found no answers on the web. I want to create a data.table with n columns, named i1 ... i'n', with only one row with value = 100 for every variable. I can do it "by hand": M.dt <- data.table(i1=100,i2=100,i3=100) but I would like to make it in a

[R] denstrip package: densregion when density is not provided

2015-10-04 Thread Matteo Richiardi
6 0.8333708 0.5612197 0.6882252 0.8183746 0.7687452 This is the error I get: Error in rank(x, ties.method = "min", na.last = "keep") : unimplemented type 'list' in 'greater' Matteo On 3 October 2015 at 09:16, Matteo Richiardi <matteo.richia...@gmail.com> wrote: &g

[R] denstrip package: densregion when density is not provided

2015-10-03 Thread Matteo Richiardi
I have several estimated time series, running from 2013 to 2050. 'y' values are constrained between 0 and 1. I would like to plot them using shaded colours of decreasing intensity, depending on an estimated density at each point x in 2013-2050. This is what I have done: require(denstrip) x <-

[R] speed issue in simulating a stochastic process

2014-11-06 Thread Matteo Richiardi
I wish to simulate the following stochastic process, for i = 1...N individuals and t=1...T periods: y_{i,t} = y_0 + lambda Ey_{t-1} + epsilon_{i,t} where Ey_{t-1} is the average of y over the N individuals computed at time t-1. My solution (below) works but is incredibly slow. Is there a faster

[R] How can I eliminate a loop over a data.table?

2013-03-19 Thread Matteo Richiardi
I've two data.tables as shown below: *** N = 10 A.DT - data.table(a1 = c(rnorm(N,0,1)), a2 = NA)) B.DT - data.table(b1 = c(rnorm(N,0,1)), b2 = 1:N) setkey(A.DT,a1) setkey(B.DT,b1) *** I tried to change my previous data.frame implementation to a data.table implementation by changing the for-loop

[R] How can I eliminate a loop over a data.table?

2013-03-18 Thread Matteo Richiardi
I've two data.tables as shown below: *** N = 10 A.DT - data.table(a1 = c(rnorm(N,0,1)), a2 = NA)) B.DT - data.table(b1 = c(rnorm(N,0,1)), b2 = 1:N) setkey(A.DT,a1) setkey(B.DT,b1) *** I tried to change my previous data.frame implementation to a data.table implementation by changing the for-loop

[R] using StatEt IDE for Eclipse

2011-12-06 Thread Matteo Richiardi
Hi, I'm trying to use StatEt IDE for Eclipse as my R editor, but I'm completely lost. I've read all I could find online, made apparently all I had to do (installing rj, configuraing StatEt, etc.) but still cannot make R running. Below is the error log file. Thank you so much for assistance. Matteo

[R] using StatEt IDE for Eclipse

2011-12-05 Thread Matteo Richiardi
Hi, I'm trying to use StatEt IDE for Eclipse as my R editor, but I'm completely lost. I've read all I could find online, made apparently all I had to do (installing rj, configuraing StatEt, etc.) but still cannot make R running. Below is the error log file. Thank you so much for assistance. Matteo

[R] efficient ways to dynamically grow a dataframe

2011-12-01 Thread Matteo Richiardi
for a matrix, because I'd loose the column names and everything will become too much error-prone. Any suggestions on how to do it? Thanks in advance, Matteo -- Matteo Richiardi University of Turin Faculty of Law Department of Economics Cognetti De Martiis via Po 53, 10124 Torino Email

[R] detecting autocorrelation structure in panel data

2011-11-27 Thread Matteo Richiardi
Hello, I'm a newby in R. I have created a data.frame holding panel data, with the following columns: id,time,y, say: periods = 100 numcases = 100 df = data.frame( id = rep(1:numcases,periods), time = rep(1:periods, each = numcases) ) df = transform(df,y=c(rnorm(numcases*periods)+id) I want to