In future, please try to provide sample data in an easy-to-copy format (as I have done in the code below). This makes it much easier for others to help you.
As nirgrahamuk pointed out, R is vectorized so you don't need loops for these kind of operations. You can directly assign the result of the computation to a new variable.
df <- data.frame(stringsAsFactors = FALSE,
date = c(as.Date("2020-07-01"), as.Date("2020-07-02")),
name = c("John", "Mary"),
earnings = c(1500, 2000),
cost = c(1250, 1500))
df$difference <- df$earnings - df$cost
df
#> date name earnings cost difference
#> 1 2020-07-01 John 1500 1250 250
#> 2 2020-07-02 Mary 2000 1500 500
Created on 2020-07-31 by the reprex package (v0.3.0)