-2

enter image description herethese month's data I have to retrieve from the dataset total number of new cases in China and India for March 2020, September 2020, March 2021, September 2021, March 2022 and September 2022

I want to get all the month data into a new data frame, I tried with data. Frame but it didn't help

  • Welcome to Stack Overflow! Please post a [minimal, reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – medium-dimensional Jan 10 '23 at 14:26
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What did you try? What errors did you get exactly? – MrFlick Jan 10 '23 at 14:28
  • I tried with few of them, I'll try to explain you the problem first. For eg: You have a dataset of an entire year with everyday entry in it. I want to retrieve only data of march from that entire data set. – uzair pawaskar Jan 10 '23 at 14:33
  • Please check the image i have just added for more information about the dataset @MrFlick – uzair pawaskar Jan 10 '23 at 14:36
  • 1
    Please [do not post code or data in images](https://meta.stackoverflow.com/q/285551/2372064). See the link I previously provided on including a reproducible example in your question. – MrFlick Jan 10 '23 at 14:37

1 Answers1

0

From the picture I cannot see what format your date string has. Assuming it is a Date variable (as.Date()), you can subset as follows:

start <- as.Date("2020-03-01")
end <- as.Date("2020-03-31")

subset <- covidData[which(covidData$date >= start & covidData$date <= end),]

This won't work, if the date column contains just characters. In this case, first convert the column:

covidData$date <- as.Date(covidData$date)