Q:

How to divide rows in new column by first / previous row?

I would like to create two columns:

That the value from the next row should be divided by the value in the first row.
In order for the value from the next row to be divided by the value from the previous line and expressed as a percentage.

Data
No    Value
1    10
2    15
3    5
4    10
5    40

Result:
1.
No    Value    V2
1    10    1
2    15    1,5
3    5     0,5
4    10    1
5    40    4

2.
No    Value    V2    V4
1    10    1    100%
2    15    1,5    150%
3    5     0,5    33,33%
4    10    1    200%
5    40    4    400%

A:

One option is
library(dplyr)
df1 %>%
  mutate(V2 = Value/first(Value), 
      V4 = 100 * Value/lag(Value, default = first(Value)) )
#No Value  V2        V4
#1  1    10 1.0 100.00000
#2  2    15 1.5 150.00000
#3  3     5 0.5  33.33333
#4  4    10 1.0 200.00000
#5  5    40 4.0 400.00000

A:

cbind(df1,
      with(df1, {
          data.frame(V2 = Value/Value[1],
                     V4 = 100* c(1, tail(Value, -1)/head(Value, -1)))
      }))
#  No Value  V2        V4
#1  1    10 1.0 100.00000
#2  2    15 1.5 150.00000
#3  3     5 0.5  33.33333
#4  4    10 1.0 200.00000
#5  5    40 4.0 400.00000

