adding +1 to quarters (dates) in R
adding and subtracting
I have the below data and I want to add a
1 to each of the quarters (i.e. push the quarter ahead by 1 quarter)
I can do
d$quarter + 1 but this gives me quarter 4 as "quarter 5". How can I roll over quarter 4 to quarter 1 of the next year?
Data: library(lubridate) dates <- sample(seq(as.Date('2005/01/01'), as.Date('2010/01/01'), by="day"), 1000) x_var <- rnorm(1000) d <- data.frame(dates, x_var) %>% mutate(quarter = quarter(dates), year = year(dates))
You can use modulo 4 to have 4 as 0 without changing 1 to 3 then add 1:
d <- data.frame(dates, x_var) %>% mutate(quarter = (quarter(dates)%%4)+1, year = year(dates))
Adding, put together (two or more numbers or amounts) to calculate their total value. v.tr. 1. To join or combine (numbers) through addition: If you add 5 and 10 and 17, the result is 32. If you add 6 to 8, you get 14.
Do it on the dates column instead
d$nextquarter <- d$dates + months(3)
Adding 8 + 7 (video), Synonyms for adding at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for adding. Adding definition, to unite or join so as to increase the number, quantity, size, or importance: to add two cups of sugar; to add a postscript to her letter; to add insult to injury.
d2 <- d %>% mutate(new_date = dates %m+% months(3)) %>% mutate(quarter2 = quarter(new_date), year2 = year(new_date))
Addition + | Basics of Arithmetic, to combine (two or more numbers or quantities) by addition. (tr foll by to) to increase (a number or quantity) by another number or quantity using addition. (tr often foll by to) to join (something) to something else in order to increase the size, quantity, effect, or scope; unite (with)to add insult to injury. Add definition is - to join or unite so as to bring about an increase or improvement. How to use add in a sentence.
Adding by making a group of 10 (video), Adding 8 + 7. About Transcript. Sal adds 8 + 7 by making a group of ten. Created by Sal Duration: 3:19 Posted: 29 Jul 2016 Synonyms for adding at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for adding.
ADDING, multiple times as required: 2 + 2 + 2. For longer lists of numbers it is usually easier to write the numbers in a column and perform the calculation at the bottom. 1 to join (something) to a mass, quantity, or number so as to bring about an overall increase the band recently added a saxophonist and a keyboard player to its ranks add another cup of flour to the mixture
Adding Synonyms, Adding Antonyms, When you add two numbers How do you know if you can make a 10? Addition (usually signified by the plus symbol +) is one of the four basic operations of arithmetic, the other three being subtraction, multiplication and division. The addition of two whole numbers results in the total amount or sum of those values combined.