How to subtract a cell from its immediate bottom cell for a column and store output in a new column in R?

20 Views Asked by At

I'm trying to subtract one cell from its immediate bottom cell, across a column and store that output in a different column.

 print(GastricT1T2mer3_cum, n=25)
# A tibble: 24 × 2
    chr   start_add
   <int>      <dbl>
 1     1          0
 2     2  248950001
 3     3  491140002
 4     4  689430003
 5     5  879640004
 6     6 1061170005
 7     7 1231970006
 8     8 1391310007
 9     9 1536440008
10    10 1674830009
11    11 1808620010
12    12 1943700011
13    13 2076970012
14    14 2191330013
15    15 2298370014
16    16 2400360015
17    17 2490690016
18    18 2573940017
19    19 2654310018
20    20 2712920019
21    21 2777360020
22    22 2824060021
23    23 2874870022
24    24 3030910023

The expected Output would look like this, where it indicates chromosome start and end position.

   # A tibble: 24 × 2
        chr   start_add      Xstart       Xend
       <int>      <dbl>       <dbl>      <dbl>
     1     1          0       0       248950000
     2     2  248950001   248950001   491140001 
     3     3  491140002   491140002   689430002
     4     4  689430003   689430003   879640003
     5     5  879640004   879640004   1061170004
     6     6 1061170005   1061170005  1231970005
0

There are 0 best solutions below