Hello. Given a vector 1 3 4 2 8 9 5 I want to obtain a vector with all 0 except in the second position and in the fifth, where the numbers are the same of the first vector. The new vector must be 0 3 0 0 8 0 0 Thank you very much. Excuseme but my mind is out of order. 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"Ambrosini Alessandro" <klavan at tiscalinet.it> writes:> Hello. > Given a vector 1 3 4 2 8 9 5 > I want to obtain a vector with all 0 except in the second position and in > the fifth, where the numbers are the same of the first vector. > The new vector must be > 0 3 0 0 8 0 0 > > Thank you very much. > Excuseme but my mind is out of order. > Alessandroy <- x y[-c(2,5)] <- 0 or y <- ifelse(1:7 %in% c(2,5), x, 0) or y <- rep(0,length(x)) y[c(2,5)] <- x[c(2,5)] -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Try x <- 1:10 x[-c(2,5)] <- 0 T. On Tue, 2002-04-30 at 15:32, Ambrosini Alessandro wrote:> Hello. > Given a vector 1 3 4 2 8 9 5 > I want to obtain a vector with all 0 except in the second position and in > the fifth, where the numbers are the same of the first vector. > The new vector must be > 0 3 0 0 8 0 0 > > Thank you very much. > Excuseme but my mind is out of order. > 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ambrosini Alessandro wrote:> > Hello. > Given a vector 1 3 4 2 8 9 5 > I want to obtain a vector with all 0 except in the second position and in > the fifth, where the numbers are the same of the first vector. > The new vector must be > 0 3 0 0 8 0 0 >x <- c(1,3,4,2,8,9,5) x[-c(2,5)] <- 0 -- Sundar Dorai-Raj, Ph.D. Statistical Methods Engineer PDF Solutions, Inc. Richardson TX (972) 889-3085 x216 (214) 392-7619 cell sundard at pdf.com -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._