[R] vector with specified values construction

Petr Pikal petr.pikal at precheza.cz
Tue Jan 31 14:56:47 CET 2006


Dear all

I want to have vector of length 24 which is filled by zeroes except 
that on position 

c(8,16,19,20) is 2
and
c(3,4,12,24) is 4
instead.
 
I am able to do

> (1:24)%in%c(8,16,19,20)*2
 [1] 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 2 2 0 0 0 0

and

> (1:24)%in%c(3,4,12,24)*4
 [1] 0 0 4 4 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 4

but I can not find a suitable construction to end with vector
0 0 4 4 0 0 0 2 0 0 0 4 0 0 0 2 0 0 2 2 0 0 0 4

Can anybody help please?


Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list