We can select rows which we want to display using the filter and arrange functions.
Syntax for filter function
You can even combine tests with boolean operators. If you use different tests separated with a comma, R just returns the 'ANDed' result ultimately. Otherwise, you can use &, | & ! operators.
Question -
1. Find out all the American Airlines flight that got cancelled after getting delayed.
Sample Code
> a <- hflights %>%
2. Display a table that contains only flights that got cancelled over weekdays.
Syntax for filter function
#1
Question -
1. Find out all the American Airlines flight that got cancelled after getting delayed.
Sample Code
> a <- hflights %>%
2. Display a table that contains only flights that got cancelled over weekdays.
Syntax for arrange function
Let's understand the role of arrange function through a question.
Question -
1. Arrange the names of all unique carriers in alphabetical order and also arrange by depdelay. Do no t include columns that might have depdelay = NA
Note: Wrapping any of the variable with desc() function will arrange the values in descending order.
We can always perform simple operations inside the arrange function directly.
Example -
> a <- hflights %>% arrange(desc(TaxiIn + TaxiOut)) > head(a)
This will arrange the data in descending order of Total Taxing Time.
No comments:
Post a Comment