indexing - index table by name in R -


I'm having trouble with dataset. The data looks like this:

  & gt; Data Name L1 1 TSS 200 1 2 TSS 200 1 3 TS 200 1 4 TSS 200 1 5 TS 200 2 6 TS 200 3 7 TSS 1500 4 TTS 1500 4 9 TSS 1500 4 10 TSS 200 4 11 TSS200 5 12 5'UTR 6 13 TSS 200 6  

And I want to increase the value based on L1, for example L1 = 1, there are 4 rows, so the index is 1 to 4; So for L1 = 2, there is only one line, so the index is 1; L2 = 3, only one line, index is 1; And so on. Production of a table like this:

  Name L1 index 1 TSS 200 1 1 2 TSS 200 1 2 3 TS 200 1 3 4 TSS 200 1 4 5 TSS 200 2 1 6 TSS 200 3 1 7 TSS 1500 4 1 8 TS 1500 4 2 9 TS 1500 4 3 10 TS 200 4 4 11 TSS 200 5 1 12 5'Utr 6 1 13 TSS 200 6 2 I hope I have a clear question Have done And thanks in advance.   

L1 is always increasing if it will work. Answer assumes that you have a data called d

  data frame (d, index = unlist (mapply (seq, 1, rle (d $ L1) $ Frame is length)) Name L1 index 1 TSS 200 1 1 2 TSS 200 1 2 3 TS 200 1 3 4 TSS 200 1 4 5 TS 200 2 1 6 TS 200 3 1 7 TS 1500 4 1 8 TS 1500 4 2 9 TSS 1500 4 3 10 TS 200 4 4 11 TS 200 5 1 12 5'UTR 6 1 13 TSS 200 6 2  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -