Select DataFrame Rows where Column Values are in Range in R Last Updated : 23 Sep, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss how to select dataframe rows where column values are in a range in R programming language. Data frame indexing can be used to extract rows or columns from the dataframe. The condition can be applied to the specific columns of the dataframe and combined using the logical operator. The logical values in terms of TRUE or FALSE are returned where the TRUE values indicate the rows satisfying the condition. The selected rows are then extracted using the returned row indexes. Syntax: dataframe[condition to define range] Example: Select rows where column values are in the range R # create first dataframe data_frame1 < -data.frame(col1=c(rep('Grp1', 2), rep('Grp2', 2), rep('Grp3', 2)), col2=rep(1: 3, 2), col3=rep(1: 2, 3), col4=letters[1:6] ) print("Original DataFrame") print(data_frame1) filtered_rows < - data_frame1$col2 >= 2 & data_frame1$col2 < 4 data_frame_mod < - data_frame1[filtered_rows, ] print("Extracted DataFrame") print(data_frame_mod) Output: [1] "Original DataFrame" col1 col2 col3 col4 1 Grp1 1 1 a 2 Grp1 2 2 b 3 Grp2 3 1 c 4 Grp2 1 2 d 5 Grp3 2 1 e 6 Grp3 3 2 f [1] "Extracted DataFrame" col1 col2 col3 col4 2 Grp1 2 2 b 3 Grp2 3 1 c 5 Grp3 2 1 e 6 Grp3 3 2 f Conditions can also be applied over multiple columns of the dataframe and connected using a logical operator. Example: Selecting columns by applying conditions over multiple columns. R # create first dataframe data_frame1<-data.frame(col1=c(rep('Grp1',2), rep('Grp2',2), rep('Grp3',2)), col2=rep(1:3,2), col3=rep(1:2,3), col4 = letters[1:6] ) print("Original DataFrame") print(data_frame1) filtered_rows <- data_frame1$col4 == 'a' | data_frame1$col3==2 data_frame_mod <- data_frame1[filtered_rows ,] print("Extracted DataFrame") print(data_frame_mod) Output: [1] "Original DataFrame" col1 col2 col3 col4 1 Grp1 1 1 a 2 Grp1 2 2 b 3 Grp2 3 1 c 4 Grp2 1 2 d 5 Grp3 2 1 e 6 Grp3 3 2 f [1] "Extracted DataFrame" col1 col2 col3 col4 1 Grp1 1 1 a 2 Grp1 2 2 b 4 Grp2 1 2 d 6 Grp3 3 2 f Comment More infoAdvertise with us Next Article Select DataFrame Rows where Column Values are in Range in R Y yashchuahan Follow Improve Article Tags : R Language R Programs R-DataFrame R DataFrame-Programs Similar Reads Select rows from a DataFrame based on values in a vector in R In this article, we will discuss how to select rows from a DataFrame based on values in a vector in R Programming Language. Method 1: Using %in% operator %in% operator in R, is used to identify if an element belongs to a vector or Dataframe. It is used to perform a selection of the elements satisfyi 5 min read Select Rows if Value in One Column is Smaller Than in Another in R Dataframe In this article, we will discuss how to select rows if the value in one column is smaller than another in dataframe in R programming language. Data frame in use: Method 1: Using Square Brackets By using < operator inside the square bracket we can return the required rows. Syntax: dataframe[datafr 2 min read Select DataFrame Column Using Character Vector in R In this article, we will discuss how to select dataframe columns using character vectors in R programming language. Data frame in use: To extract columns using character we have to use colnames() function and the index of the column to select is given with it using []. The approach is sort of the sa 2 min read Find columns and rows with NA in R DataFrame A data frame comprises cells, called data elements arranged in the form of a table of rows and columns. A data frame can have data elements belonging to different data types as well as missing values, denoted by NA. Approach Declare data frameUse function to get values to get NA valuesStore positio 3 min read Select Odd and Even Rows and Columns from DataFrame in R In this article, we will discuss how to select odd and even rows from a dataframe in R programming language. Getting Odd Rows from the Data Frame The number of rows in a data frame in R can be fetched by the nrow() method. It returns the number of rows in the data frame. The seq_len() method is then 6 min read Like