Hi all. I do not know if it is a bug in the windows version but i have this problem. Reading a file with 200000 rows, 2 columns and transforming into a 200000 x 2 matrix. If I try to find an element by using the which command which gives some correct indexes plus some others passing the 200000 row boundaries. If I try to reach those "outbound" indexs I get an "Error: subscript out of bounds" . Is this a limitation of matrix function ? or am i doing something wrong ? Example : > str(mat1) num [1:200000, 1:2] 185 212 222 269 342 349 361 367 397 423 ... > which(mat1 == 185) [1] 1 201920 203792 205211 206604 220417 223767 225169 239420 243768 249351 249395 252077 What could be happening ? Thanks in advance Mark Marques
On Thu, 20 Mar 2003, Mmarques INESC wrote:> Hi all. > I do not know if it is a bug in the windows version but i have this > problem. > Reading a file with 200000 rows, 2 columns and transforming into a > 200000 x 2 matrix. > If I try to find an element by using the which command which gives > some correct indexes plus some others passing the 200000 row > boundaries. > If I try to reach those "outbound" indexs I get an "Error: subscript out > of bounds" . > Is this a limitation of matrix function ? or am i doing something > wrong ? > Example : > > > str(mat1) > num [1:200000, 1:2] 185 212 222 269 342 349 361 367 397 423 ...> [1] 1 201920 203792 205211 206604 220417 223767 225169 239420 243768 249351 249395 252077 > What could be happening ? > > which(mat1 == 185)mat1 is a matrix 200000x2 but also a vector of length 400000. Try> ?whichand> which(mat1 == 185, arr.ind = TRUE)G?ran --- G?ran Brostr?m tel: +46 90 786 5223 Department of Statistics fax: +46 90 786 6614 Ume? University http://www.stat.umu.se/egna/gb/ SE-90187 Ume?, Sweden e-mail: gb at stat.umu.se
It 'unwraps' the 200,000 x 2 matrix into a vector with 400,000 elements and giving you the location/subscripts of this vector that matches the criterion. Instead you should use apply(mat1, 2, function(y) which( y == 2 )) which gives you the rows in each column that corresponds to 185. Try length(mat1) and dim(mat1) and you will see that for length(), it coerces the object into a vector first. -----Original Message----- From: Mmarques INESC [mailto:mmarques at inescporto.pt] Sent: Thursday, March 20, 2003 7:49 PM To: R-help Mailing list. Subject: [R] Matrix problems Hi all. I do not know if it is a bug in the windows version but i have this problem. Reading a file with 200000 rows, 2 columns and transforming into a 200000 x 2 matrix. If I try to find an element by using the which command which gives some correct indexes plus some others passing the 200000 row boundaries. If I try to reach those "outbound" indexs I get an "Error: subscript out of bounds" . Is this a limitation of matrix function ? or am i doing something wrong ? Example : > str(mat1) num [1:200000, 1:2] 185 212 222 269 342 349 361 367 397 423 ... > which(mat1 == 185) [1] 1 201920 203792 205211 206604 220417 223767 225169 239420 243768 249351 249395 252077 What could be happening ? Thanks in advance Mark Marques ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help