Re: [R] [External] converting MATLAB -> R | element-wise operation

2024-02-29 Thread Evan Cooch
Very interesting - thanks! Most of my problems are not limited by compute speed, but its clear that for some sorts of compute-intensive problems, sweep might be a limiting approach. On 2/29/2024 6:12 PM, Richard M. Heiberger wrote: > I decided to do a direct comparison of transpose and sweep. >

Re: [R] [External] converting MATLAB -> R | element-wise operation

2024-02-29 Thread Richard M. Heiberger
I added two more rows library(microbenchmark) NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE) # Example matrix lambda <- c(2, 3, 4) # Example vector colNN <- t(NN) matlam <- matrix(lambda, byrow=TRUE, nrow=2, ncol=3) microbenchmark( sweep = sweep(NN, 2, lambda, "/"), transpos

Re: [R] Clustering Functions used by Reverse-Dependencies

2024-02-29 Thread Leo Mada via R-help
Dear Ivan, Thank you very much for this interesting information. Regarding: "For well-behaved packages that declare their dependencies correctly, parsing the NAMESPACE for importFrom() and import() calls should give you the explicit imports." I did learn something new (I am not very experienced

Re: [R] [External] converting MATLAB -> R | element-wise operation

2024-02-29 Thread Richard M. Heiberger
I decided to do a direct comparison of transpose and sweep. library(microbenchmark) NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE) # Example matrix lambda <- c(2, 3, 4) # Example vector colNN <- t(NN) microbenchmark( sweep = sweep(NN, 2, lambda, "/"), transpose = t(t(NN)/la

[R] R 4.3.3 is released

2024-02-29 Thread Peter Dalgaard via R-announce
The build system rolled up R-4.3.3.tar.gz and .xz (codename "Angel Food Cake") this morning. This is a minor update, intended as the wrap-up release for the 4.3.x series. This also marks the 6th anniversary of R-1.0.0. (2000-02-29) The list below details the changes in this release. You can

Re: [R] Initializing vector and matrices

2024-02-29 Thread Steven Yen
Thanks to all. Great ideas. I found Eik Vettorazzi's suggesstion easy to implrment: ebarm<-vbarm<-NULL ... if (is.null(ebarm)) ebarm<-ame.00$ei/k else ebarm<-ebarm+ame.00$ei/k if (is.null(vbarm)) vbarm<-ame.00$vi/k else vbarm<-vbarm+ame.00$vi/k ... Steven Yen On 2/29/2024 10:31 PM, Ebert,Timo

Re: [R] Initializing vector and matrices

2024-02-29 Thread Ebert,Timothy Aaron
You could declare a matrix much larger than you intend to use. This works with a few megabytes of data. It is not very efficient, so scaling up may become a problem. m22 <- matrix(NA, 1:60, ncol=6) It does not work to add a new column to the matrix, as in you get an error if you try m22[ ,

Re: [R] Initializing vector and matrices

2024-02-29 Thread Richard O'Keefe
x <- numeric(0) for (...) { x[length(x)+1] <- ... } works. You can build a matrix by building a vector one element at a time this way, and then reshaping it at the end. That only works if you don't need it to be a matrix at all times. Another approach is to build a list of rows. It's not a ma

Re: [R] [EXT] Re: Initializing vector and matrices

2024-02-29 Thread Eik Vettorazzi
Dear Steven, I used "sample" just to generate a non-trivial example, you could insert your code of generating the real xi at this point :-) If you want to stick to for-loops for some reasons, something like this could work x<-NULL for (i in 1:5){ xi<-1:5 if (is.null(x)) x<-xi else x<-x+

Re: [R] [EXT] Initializing vector and matrices

2024-02-29 Thread Steven Yen
Hello Eik: Thanks. I do not need to sample. Essentially, I have a do loop which produces 24 vectors of length of some length (say k=300) and 24 matrices of 300x300. Then, I simply need to  take the averages of these 24 vectors and matrices: x=(x1+x2+...+x24)/k y=(y1+y2+...+y24)/k I am just