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.
Contact Us