How to use select() method In R Language

For this functionality, select() function accepts 2 parameters, first is the filter function and the second is a vector of column names,

Syntax: select(filter(df, condition, columns)

Parameters:

df: dataframe object

condition: filtering condition

columns: vector of column names which you want to print

filter() works almost the same way as given above, the only difference being the vector of column names which we are passing in the second argument. This prints only the columns that were passed in the select function. In this way we can print selected columns only.

Example: Printing selected rows

R




library(dplyr)
  
df <- data.frame(prep = c(11:15),
                 str = c("Welcome", "to", "Geeks"
                         "for", "Geeks"),
                 date=c("Sunday","Monday", "Thursday",
                        "January","December"))
  
  
select(filter(df, date %in% c("January", "Monday")), c(date,prep))


Output:

      date prep
1  Monday   12
2 January   14


Filter multiple values on a string column in R using Dplyr

In this article we will learn how to filter multiple values on a string column in R programming language using dplyr package.

Similar Reads

Method 1: Using filter() method

filter() function is used to choose cases and filtering out the values based on the filtering conditions....

Method 2: Using filter() with %in% operator

...

Method 3: Using select() method

In this, first, pass your dataframe object to the filter function, then in the condition parameter write the column name in which you want to filter multiple values then put the %in% operator, and then pass a vector containing all the string values which you want in the result. This produces all the rows containing the string values in the specified column....