[R] Insert value in a Vector Alternately

Gundala Viswanath gundalav at gmail.com
Thu Feb 19 07:47:40 CET 2009


Hi,

I have a vector that look like this:

> dat
             V1         V2         V3         V4         V5         V6
 0.00377467 0.00377467 0.00377467 0.00380083 0.00380083 0.00380083
             V7         V8         V9        V10        V11        V12
 0.00380959 0.00380959 0.00380959 0.00380083 0.00380083 0.00380083


what I want to do is to insert 0 (zero) for every 3 position yielding:

V1   V2              V3                V4             V5    V6
    V7               V8
0  0.00377467 0.00377467 0.00377467 0  0.00380083 0.00380083 0.00380083
V9   V10              V11                V12             V13    V14
        V15             V16
0 0.00380959 0.00380959 0.00380959 0 .00380083 0.00380083 0.00380083


Is there a quick way to do it in R?

- Gundala Viswanath
Jakarta - Indonesia




More information about the R-help mailing list