-2

I have pooled data from 2000-2005. I want to do these three things:

1) How to delete a specific month from all the years? For example, I want to delete June from each year? what would be the code for that?

2) Moreover, what if I want to delete for example 3 months, June, July, and August. what would be the code then?

Sorry, I am newbie in R and need a little help.

  • 1
    Dear Hasan. Welcome to SO! Please take the [tour](https://stackoverflow.com/tour) and have a look at [how to ask a good question](https://stackoverflow.com/help/how-to-ask) and [how to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – 4rj4n Jan 28 '20 at 11:09

1 Answers1

0

Assuming you have dataframe called data with Date column in it. Convert it into date object.

data$Date <- as.Date(data$Date)

You can extract the month from it and delete data of June

data[as.integer(format(data$Date, "%m")) != 6, ]

Or delete data of June, July, and August

data[!as.integer(format(data$Date, "%m")) %in% 6:8, ]
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213