Subset DataFrame Between Two Dates in R Last Updated : 11 Oct, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we are going to get the data between two dates in dataframe in R Programming Language. We can create a column to store date using as.Date() function Syntax: as.Date('yyyy-mm-dd') Example: Creating dataframe R # create a dataframe with 6 rows and 2 columns # one column is of 6 dates with date type as # year-month-day format # second is temperature degrees data = data.frame(date=c(as.Date('2020-6-6'), as.Date('2021-12-1'), as.Date('2021-11-27'), as.Date('2020-6-1'), as.Date('2019-6-6'), as.Date('2017-12-1')), temperature=c(43, 41, 34, 33, 40, 29)) # display print(data) Output: We are going to subset the data between date ranges using logical operators. Thus, we need less than(<), greater than(>), and the and(&) operator. Syntax: dataframe[dataframe$date_column> "start_date" & dataframe$date_column < "end_date", ] where, dataframe is the input dataframedate_column is the date column in the dataframedate is the date specified to get the data from start_date to end_date Example: R program to get the data from the given date ranges R # create a dataframe with 6 rows and 2 columns # one column is of 6 dates with date type as # year-month-day format # second is temperature degrees data=data.frame(date=c(as.Date('2020-6-6'), as.Date('2021-12-1'), as.Date('2021-11-27'), as.Date('2020-6-1'), as.Date('2019-6-6'), as.Date('2021-10-12')), temperature=c(43,41,34,33,40,29)) # subset the dataframe from 1 st january 2021 # to 1 st October 2022 print(data[data$date > "2021-01-01" & data$date < "2022-10-01", ]) Output: Example: R program to get the data from the given date ranges R # create a dataframe with 6 rows and 2 columns # one column is of 6 dates with date type as # year-month-day format # second is temperature degrees data=data.frame(date=c(as.Date('2020-6-6'), as.Date('2021-12-1'), as.Date('2021-11-27'), as.Date('2020-6-1'), as.Date('2019-6-6'), as.Date('2017-10-12')), temperature=c(43,41,34,33,40,29)) # subset the dataframe from 11th november 2017 # to 1 st October 2019 print(data[data$date > "2017-11-11" & data$date < "2019-10-01", ]) Output: Comment More infoAdvertise with us Next Article How to Select DataFrame Columns by Index in R? S sravankumar_171fa07058 Follow Improve Article Tags : R Language R Programs R-DataFrame R DataFrame-Programs Similar Reads How to Sort a DataFrame by Date in R? In this article, we will discuss how to sort a dataframe in R Programming Language. We can create a dataframe in R by using data.frame() function. In a dataframe we can create a date column using as.Date() function in the '%m/%d/%Y' format. Example: Let's create a dataframe with 2 columns including 2 min read How to remove a subset from a DataFrame in R ? A subset is a combination of cells that form a smaller data frame formed out from the original data frame. A set of rows and columns can be removed from the original data frame to reduce a part of the data frame. The subset removal can be based on constraints to which rows and columns are subjected 4 min read Convert dataframe column to datetime in R The string-type date objects do not offer easy parsing and manipulation of the components. The conversion of date objects to POSIXct or POSIXlt objects can help in the easy conversion of dates to the required formats with desirable time zones. In this article, we will discuss how to convert datafram 4 min read How to Select DataFrame Columns by Index in R? In this article, we will discuss how to select columns by index from a dataframe in R programming language. Note: The indexing of the columns in the R programming language always starts from 1. Method 1: Select Specific Columns By Index with Base R Here, we are going to select columns by using index 2 min read Convert DataFrame with Date Column to Time Series Object in R In this article, we will discuss how to convert dataframe with date column to time series object in the R programming language. Time series object are a series of data points in which each data point is associated with a timestamp. For example, is a price of a stock in the stock market at different 2 min read How to Select Specific Columns in R dataframe? In this article, we will discuss how to select specific columns from a data frame in the R Programming Language. Selecting specific Columns Using Base R by column nameIn this approach to select a specific column, the user needs to write the name of the column name in the square bracket with the name 7 min read Like