The first: if I have a vector as (1,1,3,2,1,1), which is the command that gives all the positions of the min value? From the vector of the example a would like to obtain a new vector as (1,2,5,6) that give me all the positions of the minimum value 1. The second: if I have a matrix "A" and I want to obtain a new matrix deleting a column or a row of A, what have I to do? Thank you. Alessandro -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Monday 15 April 2002 14:54, Ambrosini Alessandro wrote:> The first: if I have a vector as (1,1,3,2,1,1), which is the command that > gives all the positions of the min value? From the vector of the example a > would like to obtain a new vector as (1,2,5,6) that give me all the > positions of the minimum value 1.which(x==min(x))> > The second: if I have a matrix "A" and I want to obtain a new matrix > deleting a column or a row of A, what have I to do? > Thank you. > AlessandroA[,-1] and A[-1,] give you matrix A without the first column or row, respectively. Ron -- Ron Wehrens Dept. of Chemometrics University of Nijmegen Email: rwehrens at sci.kun.nl Toernooiveld 1 http://www-cac.sci.kun.nl/cac/ 6525 ED Nijmegen Tel: +31 24 365 2053 The Netherlands Fax: +31 24 365 2653 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ambrosini Alessandro wrote:> > The first: if I have a vector as (1,1,3,2,1,1), which is the command that > gives all the positions of the min value? From the vector of the example a > would like to obtain a new vector as (1,2,5,6) that give me all the > positions of the minimum value 1.which(x == min(x))> The second: if I have a matrix "A" and I want to obtain a new matrix > deleting a column or a row of A, what have I to do?A.new <- A[-k,] # delete the k-th row A.new <- A[-k,] # delete the k-th column Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 15 Apr 2002, Ambrosini Alessandro wrote:> The first: if I have a vector as (1,1,3,2,1,1), which is the command that > gives all the positions of the min value? From the vector of the example ax <- c(1,1,3,2,1,1) wm <- which.min(x) # first position> would like to obtain a new vector as (1,2,5,6) that give me all the > positions of the minimum value 1.which(x == wm)> > The second: if I have a matrix "A" and I want to obtain a new matrix > deleting a column or a row of A, what have I to do?A <- matrix(1:25, ncol=5) A[-2,-4] # delete 2nd row and 4th col [,1] [,2] [,3] [,4] [1,] 1 6 11 21 [2,] 3 8 13 23 [3,] 4 9 14 24 [4,] 5 10 15 25 Torsten> Thank you. > Alessandro > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 15 Apr 2002, Ambrosini Alessandro wrote:> The first: if I have a vector as (1,1,3,2,1,1), which is the command that > gives all the positions of the min value? From the vector of the example a > would like to obtain a new vector as (1,2,5,6) that give me all the > positions of the minimum value 1.> x <- c(1,1,3,2,1,1) > which(x == min(x))[1] 1 2 5 6> > > The second: if I have a matrix "A" and I want to obtain a new matrix > deleting a column or a row of A, what have I to do? > Thank you.A[-1, ] removes the first row, etc. G?ran -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
(Reply to Ambrosini Alessandro)> The first: if I have a vector as (1,1,3,2,1,1), which is the command that > gives all the positions of the min value? From the vector of the example a > would like to obtain a new vector as (1,2,5,6) that give me all the > positions of the minimum value 1.> x <- c(1,1,3,2,1,1) > x[x==min(x)][1] 1 1 1 1> which(x==min(x))[1] 1 2 5 6>> The second: if I have a matrix "A" and I want to obtain a new matrix > deleting a column or a row of A, what have I to do?> A[,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9> A[,-2][,1] [,2] [1,] 1 7 [2,] 2 8 [3,] 3 9> A[-2,][,1] [,2] [,3] [1,] 1 4 7 [2,] 3 6 9>That's the solutions. Christoph. -- Christoph Lange clange at epost.de Verhaltensbiologie, FU Berlin 838-55068 Haderslebener Str. 9, 12163 Berlin http://www.verhaltensbiologie.fu-berlin.de/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ambrosini Alessandro <klavan at tiscalinet.it> writes:>The first: if I have a vector as (1,1,3,2,1,1), which is the command that >gives all the positions of the min value? From the vector of the example a >would like to obtain a new vector as (1,2,5,6) that give me all the >positions of the minimum value 1.Something like: (1:length(x))[x == min(x)] Does it. There is also a which() function: which(x == min(x)) This does it too.>The second: if I have a matrix "A" and I want to obtain a new matrix >deleting a column or a row of A, what have I to do?Use negated row and column indices: m <- matrix(1:12, nrow = 3) # drop the second row m[-2, ] # drop the second column m[ ,-2]>Hello! If I have a matrix as 1 2 > 2 3 >and I want to change the value 2 in 0, what can I do?m <- matrix(c(1, 2, 2, 3), nrow = 2) m[m == 2] <- 0 m I Hope that helps. These sorts of questions are dealt with very fully in most of the introductory texts available in the help system and from the CRAN website. Mark -- Mark Myatt -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._