bunny , lautloscrew.com
2007-Mar-01 19:08 UTC
[R] problem with throwing lines out of matrix
Dear all, again i have a problem with special case of dropping lines out of a matrix. i tried the following, where throwout is a vector of length 18 with simple id values that should be compared to any for (k in 1:length(throwout)) { mymatrix=matrix(mymatrix[-(forfact[k]),],ncol=4) } this didnt work and i tried the following to find the error: mymatrix[,1][mymatrix[,1]==throwout[7]] this returned me a nice value - everything fine... but other same other values for throwout didnt work - because the throwout value simply is not in this matrix. but i need the same throwout vector for different matrices - so i need to use it. does anybody have an idea how i can throw out all lines in every of my 5 matrices that contain values of the throwout in their first column ? and how to deal with the problem that not every matrix contains all throwout values in its first column... maybe this might help: in the end all matrices should have the same number of lines. thx in advance, i´ll keep on trying ;) [[alternative HTML version deleted]]
Wiener, Matthew
2007-Mar-01 19:46 UTC
[R] problem with throwing lines out of matrix [Broadcast]
You didn't' actually tell us what forfact is. You could try something like (untested) My.matrix <- my.matrix[!(my.matrix[, 1] %in% remove.values), , drop = FALSE] Also, reading some of the introductory R manuals you can find on CRAN in the documentation section will really give you a leg up on some of these things. Hope this helps. Matt Wiener -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of bunny , lautloscrew.com Sent: Thursday, March 01, 2007 2:09 PM To: r-help at stat.math.ethz.ch Subject: [R] problem with throwing lines out of matrix [Broadcast] Dear all, again i have a problem with special case of dropping lines out of a matrix. i tried the following, where throwout is a vector of length 18 with simple id values that should be compared to any for (k in 1:length(throwout)) { mymatrix=matrix(mymatrix[-(forfact[k]),],ncol=4) } this didnt work and i tried the following to find the error: mymatrix[,1][mymatrix[,1]==throwout[7]] this returned me a nice value - everything fine... but other same other values for throwout didnt work - because the throwout value simply is not in this matrix. but i need the same throwout vector for different matrices - so i need to use it. does anybody have an idea how i can throw out all lines in every of my 5 matrices that contain values of the throwout in their first column ? and how to deal with the problem that not every matrix contains all throwout values in its first column... maybe this might help: in the end all matrices should have the same number of lines. thx in advance, i?ll keep on trying ;) [[alternative HTML version deleted]] ------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}