Creating new variables by writing a function

Hi, next time please provide a reproducible example instead of a screenshot.

Anyway, here is some code that should work. You could also calculate the absolute difference with the abs() function.

library(tidyverse)

# tidyverse way
spruce <- spruce %>% 
  mutate(diff = Grass - Spruce) 


# base R way
spruce$diff <- spruce$Grass - spruce$Spruce