Re: [R] Initializing vector and matrices

2024-03-02 Thread Jeff Newmiller via R-help
sed space in a matrix is the >> > amount of memory it takes. One side effect is that your program may have a >> > mistake that you would normally catch with a subscript out of bounds error >> > but with the extra space it now runs without errors. >> > >> > Tim

Re: [R] Initializing vector and matrices

2024-03-02 Thread Bert Gunter
ect is that your program may have a > > mistake that you would normally catch with a subscript out of bounds error > > but with the extra space it now runs without errors. > > > > Tim > > > > > > > > -Original Message- > > From: R-help

Re: [R] Initializing vector and matrices

2024-03-02 Thread Richard O'Keefe
atch with a subscript out of bounds error > but with the extra space it now runs without errors. > > Tim > > > > -Original Message- > From: R-help On Behalf Of Richard O'Keefe > Sent: Thursday, February 29, 2024 5:29 AM > To: Steven Yen > Cc: R-help Mailin

Re: [R] Initializing vector and matrices

2024-02-29 Thread Steven Yen
you would normally catch with a subscript out of bounds error but with the extra space it now runs without errors. Tim -Original Message- From: R-help On Behalf Of Richard O'Keefe Sent: Thursday, February 29, 2024 5:29 AM To: Steven Yen Cc: R-help Mailing List Subject: Re:

Re: [R] Initializing vector and matrices

2024-02-29 Thread Ebert,Timothy Aaron
pt out of bounds error but with the extra space it now runs without errors. Tim -Original Message- From: R-help On Behalf Of Richard O'Keefe Sent: Thursday, February 29, 2024 5:29 AM To: Steven Yen Cc: R-help Mailing List Subject: Re: [R] Initializing vector and matrices [Exte

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] Initializing vector and matrices

2024-02-28 Thread Steven Yen
OK. I initialize real large vector and matrix and then shrink them when I use them in the loop. The following lines worked. I'd glad to know of better approaches. bsum<-rep(0,1000); bsum vsum<-matrix(rep(0,100),nrow=1000); vsum for (ind in 1:3) { mydata <- read.csv(paste0("midata", ind, ".c

[R] Initializing vector and matrices

2024-02-28 Thread Steven Yen
Is there as way to initialize a vector (matrix) with an unknown length (dimension)? NULL does not seem to work. The lines below work with a vector of length 4 and a matrix of 4 x 4. What if I do not know initially the length/dimension of the vector/matrix? All I want is to add up (accumulate)