Home > Blockchain >  I have to extract data from a Colum in a dataset by month
I have to extract data from a Colum in a dataset by month

Time:01-11

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

CodePudding user response:

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)
  •  Tags:  
  • r
  • Related