Inactive Tutor answered 08/27/19
Tutor
New to Wyzant
Hello,
Whenever I am manipulating data in R, I have found that the dplyr package can be quite useful. For your question, I used the mutate function, which can create a new column using existing columns. Please reference the below code and let me know if this helps!
## Load the dplyr package
library(dplyr)
## Generate Data
TIME_DAY <- c(10,10,15,5,45,30,60,15)
data <- data.frame(TIME_DAY)
## Create the column 'DIFF' by subtracting 1 from the column 'TIME_DAY' using the ## mutate function from dplyr
new_data <-
data %>% mutate(DIFF <- TIME_DAY - 1)
head(new_data)