0

I'm having some issues defining a certain amount of rows (5 rows) prior to a given row with a value = 1. Dataframe showing an example of five rows i want to have coded -1 under the new column

I would like to create a new column with following conditions:

Date_start is the number a the week given a certain year in a specific country.

The new column that I want is a "Pre-Ceasefire" column, defining a period before a ceasefire was put into effect.

Every time the column "Ceasefires" has a value = 1 I would like to go back 5 rows (weeks) and give these rows the value of -1 in the column called "Pre-Ceasefire".

To be fair, I wouldn't really now where to start. It might be a very easy solution to the problem, but I dont know how to solve the problem of telling the code that "date_start" is a week conditioned on a given year.

  • 2
    Welcome to SO. Please do not upload images of data. You can provide a `dput(df)` to create a [Minimum Reproductible Example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can reproduce the situation on our machine. – Benson_YoureFired Nov 24 '22 at 16:31

0 Answers0