[R] A sample question

Sundar Dorai-Raj sundard at pdf.com
Wed May 1 00:46:36 CEST 2002



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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list