[R] detecting if a variable has changed

2016-06-05 Thread Neal H. Walfield
Hi, I have a huge list. Normally it is sorted, but I want to be able to add elements to it without having to use any special interfaces and then sort it on demand. My idea is to use something like weak references combined with attributes. Consider: # Initialization. l = as.list(1:10) # N

Re: [R] detecting if a variable has changed

2016-06-05 Thread Neal H. Walfield
RUE > > > > x$getData() > > > [1] 1 2 4 5 8 9 > > > > x > > > Reference class object of class "sortedNumeric" > > > Field "fData": > > > [1

Re: [R] detecting if a variable has changed

2016-06-05 Thread Neal H. Walfield
TRUE > > } > > )) > > > > Use it as: > > > >> x <- SortedNumeric$new() > >> x$appendData(c(4,2,5)) > >> x$appendData(c(1,8,9)) > >> x > > Reference class object of class "sortedNumeric" > >

[R] %in% with matrix of lists

2016-07-30 Thread Neal H. Walfield
I have a matrix of lists. Something along the lists of (but much bigger than): x = array(dim=c(2, 2), data=list()) x[1,1] = list(1:5) x[2,1] = list(6:9) x[1,2] = list(10:13) x[2,2] = list(14:16) Each list contains a number of observations/ground truth for a particular state. That is,

Re: [R] %in% with matrix of lists

2016-07-30 Thread Neal H. Walfield
On Sat, 30 Jul 2016 19:28:42 +0200, Bert Gunter wrote: > Bottom line: No, I dont see any vectorized way to do this. > > However, the following may offer some slight improvement over your approach. > > 1. Why do you need to store these as arrays, which are merely vectors > with a "dim" attribute?

Re: [R] %in% with matrix of lists

2016-07-30 Thread Neal H. Walfield
On Sat, 30 Jul 2016 20:35:40 +0200, Jeff Newmiller wrote: > > >> [1] TRUE FALSE TRUE FALSE ## NOT c(T,F,T,F) > > > >I'm not sure what you mean by NOT here. You get the same answer as I > >do, as far as I can see. > > > > # valid R > T <- FALSE > # invalid R > TRUE <- FALSE > > It is much muc

[R] write.table produces a file that read.table can't read

2014-10-08 Thread Neal H. Walfield
Hi, I'm using R version 3.1.1 on Debian via the CRAN repositories. Consider the following MWE that writes a data.frame out to a file and reads it back in (note that one of the strings contains a double quote): > write.table(data.frame(a=1:3, b=c("a", "b\"b", "c")), '/tmp/a', row.names=FALSE,

Re: [R] vectorization & modifying globals in functions

2012-12-27 Thread Neal H. Walfield
At Thu, 27 Dec 2012 15:38:08 -0500, Sam Steingold wrote: > so, > 1. is there a way for a function to modify a global variable? Use <<- instead of <-. > 2. how would you vectorize this loop? This is hard. Your function has a feedback loop: an iteration depends on the previous iteration's result.

Re: [R] parallel error message extraction (in mclapply)?

2012-12-29 Thread Neal H. Walfield
Hi, Ivo, At Fri, 28 Dec 2012 16:34:03 -0800, ivo welch wrote: > so, it isn't obvious to me how I get to the try-error object > list, or how to find out what triggered the abort. A try object is an object that captures the execution context at the time of an error. Consider the following code:

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread Neal H. Walfield
At Sun, 30 Dec 2012 18:26:45 +0800 (CST), meng wrote: > > hi all: > Here's a dataframe(dat) and a vector(z): > > dat: > x1 x2x3 > 0.2 1.2 2.5 > 0.5 2 5 > 0.8 3 6.2 > > > z > [1] 10 100 100 > > I wanna do the following: > 10*x1,100*x2,1000*x3 > > My solution is us

Re: [R] How to multiple the vector and variables from dataframe

2012-12-30 Thread Neal H. Walfield
ou mean multiplied by element. Here's a better solution using t to transpose the matrix: dat=data.frame(x1=1:3, x2=11:13) as.matrix(dat) x1 x2 [1,] 1 11 [2,] 2 12 [3,] 3 13 t(as.matrix(dat)) * c(2, 3) [,1] [,2] [,3] x1246 x2 33 36 39 > > Andrius >

Re: [R] group values in classes

2012-12-31 Thread Neal H. Walfield
At Mon, 31 Dec 2012 12:13:43 +0200, catalin roibu wrote: > > Dear R users, > I want to group numerical values in classes with different size and count > the values for each classes. > > My data is in this forma: > d 15 12,5 30,4 20,5 80,4 100,5 8,2 40,5 33 21 11 > And I want the group

Re: [R] Installing R-2.15.2 in Debian Wheezy/Testing

2012-12-31 Thread Neal H. Walfield
At Mon, 31 Dec 2012 15:38:10 -0500, Stephen P. Molnar wrote: > The current version of R that is available in Wheezy is 2.15.1. However, > version 2.15.2 is available at CRAN sites. > ... > My question is what should be the format of the line in the sources.lists? Here's what I have: deb http:/

Re: [R] cut ()

2012-12-31 Thread Neal H. Walfield
At Mon, 31 Dec 2012 22:25:25 +, Muhuri, Pradip (SAMHSA/CBHSQ) wrote: > The issue is that, for Utah, I am getting an instead of (42,48.7] in the > ob_mrj_cat column. The problem is likely due to comparisons of floating point numbers. Try moving your lower and upper bounds out a tiny bit. Whe

Re: [R] cut ()

2013-01-01 Thread Neal H. Walfield
At Tue, 1 Jan 2013 02:00:14 +, Muhuri, Pradip (SAMHSA/CBHSQ) wrote: > Although David's solution (putting the right parenthesis, which I had missed) > has resolved the issue, I would like to try yours as well. > > Could you please clarify the six elements: c(-1e-8, 0, 0, 0, 0, 1e8)? It's a v

Re: [R] Working with Matrix

2013-01-04 Thread Neal H. Walfield
At Fri, 4 Jan 2013 17:17:40 +0530, Christofer Bogaso wrote: > > Hello again, > > Let say I have 2 matrices which equal number of columns but different > number of rows like: > > Mat1 <- matrix(1:20, 4, 5) > Mat2 <- matrix(1:25, 5, 5) > > Now for each column 1-to-5 I need to fetch the correspond

Re: [R] Combinations

2013-03-15 Thread Neal H. Walfield
At Fri, 15 Mar 2013 09:22:15 -0400, Amir wrote: > I have two sets T1={c1,c2,..,cn} and T2={k1,k2,...,kn}. > How can I find the sets as follow: > > (c1,k1), (c1,k2) ...(c1,kn) (c2,k1) (c2,k2) (c2,kn) ... (cn,kn) I think you are looking for expand.grid: expand.grid(1:3, 10:13) Var1 Var2 1