[R] two questions
Mark Myatt
mark at myatt.demon.co.uk
Tue Apr 16 11:27:29 CEST 2002
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list