R help: grouping bonds into 10 decile each row
<p>As mentioned in the subject I am trying my best to group the bonds into 10 
decile each row. </p>

<p>So currently my data looks like as below. The columns are IDs of 
the bonds and they are ranked *each month. *Now I am trying to group these 
ranks into 10 deciles (e.g. assume in 05/2015 there were 100 valid bonds, 
then ranks 1~10 will be group 1, ranks 11~20 group 2 and so on... ) </p>

<pre><code>    date       a        b        c        d        e         f        g       h ...
    05/15      8        6        3        2        1         4        5       7 ...
    06/15      7        8        4        3        2         6        5       1 ...
    07/15      3        5        6        7        2         1        4       8 ...
    ...      
</code></pre>

<p>and this is what I have been trying to do. </p>

<pre><code>     for (i in 1:116) 
     {for (j in 1:283) {if (j &lt;=max.col(i)/10){print j = 1} 
     else if ( max.col(i)/10&lt;j&lt;=max.col(i)*2/10){print j = 2}
     else if ( max.col(i)*2/10&lt;j&lt;=max.col(i)*3/10){print j = 3}
     else if ( max.col(i)*3/10&lt;j&lt;=max.col(i)*4/10){print j = 4}
     else if ( max.col(i)*4/10&lt;j&lt;=max.col(i)*5/10){print j = 5}
     else if ( max.col(i)*5/10&lt;j&lt;=max.col(i)*6/10){print j = 6}
     else if ( max.col(i)*6/10&lt;j&lt;=max.col(i)*7/10){print j = 7}
     else if ( max.col(i)*7/10&lt;j&lt;=max.col(i)*8/10){print j = 8}
     else if ( max.col(i)*8/10&lt;j&lt;=max.col(i)*9/10){print j = 9}
     else if ( max.col(i)*9/10&lt;j&lt;=max.col(i)*10/10){print j = 10}
      }}
</code></pre>

<p>I am new to R and this was the best I could think of. Please help. 
Can I use quantile function to do this....?</p>

<p>Thanks, 
hk</p>

<p>[update] </p>

<p>I have tried modifying the loop and still gets an error </p>

<pre><code>     for (i in 1:dim(bondsr3)[1])
     {for (j in 1:dim(bondsr3)[2]) {
     if (is.na(bondsr3[i,j])) { }
     else if (as.numeric(bondsr3[i,j]) &lt;= max.col(i)%/%10){bondsr4[i,j]&lt;-2}
     else if ( max.col(i)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=(max.col(i)%*%2)%/%10){bondsr4[i,j]&lt;-2}
     else if ( (max.col(i)%*%2)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=(max.col(i)%*%3)%/%10){bondsr4[i,j]&lt;-3}
     else if ( (max.col(i)%*%3)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=(max.col(i)%*%4)%/%10){bondsr4[i,j]&lt;-4}
     else if ( (max.col(i)%*%4)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=(max.col(i)%*%5)%/%10){bondsr4[i,j]&lt;-5}
     else if ( (max.col(i)%*%5)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=(max.col(i)%*%6)%/%10){bondsr4[i,j]&lt;-6}
     else if ( (max.col(i)%*%6)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=(max.col(i)%*%7)%/%10){bondsr4[i,j]&lt;-7}
     else if ( (max.col(i)%*%7)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=(max.col(i)%*%8)%/%10){bondsr4[i,j]&lt;-8}
     else if ( (max.col(i)%*%8)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=(max.col(i)%*%9)%/%10){bondsr4[i,j]&lt;-9}
     else if ( (max.col(i)%*%9)%/%10&lt;as.numeric(bondsr3[i,j]) &amp; as.numeric(bondsr3[i,j])&lt;=max.col(i)){bondsr4[i,j]&lt;- 10}}}
</code></pre>

<p>but I still get this error message...</p>

<pre><code>      Warning message:
      In `[&lt;-.factor`(`*tmp*`, iseq, value = 10) :
      invalid factor level, NA generated
</code></pre>

<p>My desired output is to get 1 for all rankings 1to 10 and 2 from 11 to 20 ... 10 from 91 to 100 where valid number of bonds at a certain month is 100.</p>

<p>Any help would be appreciated.</p>