Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Filtering Data - Basic Conditions | Data Manipulation and Cleaning
Data Analysis with R

bookFiltering Data - Basic Conditions

メニューを表示するにはスワイプしてください

Filtering is a powerful technique that allows you to isolate rows of data that meet certain criteria - like only selecting diesel cars, expensive cars, or vehicles with manual transmission. It helps you focus on relevant data for deeper analysis, reporting, or visualization.

Filtering by Category

Base R

You can filter rows by applying a condition to a specific column. For example, to select only the cars where the fuel type is Diesel, use the $ operator to reference the column and apply a logical condition.

diesel_cars <- df[df$fuel == "Diesel", ]

dplyr

You can use the filter() function and pass the condition directly.

diesel_cars_dplyr <- df %>%    
  filter(fuel == "Diesel")

Filtering Based on Numeric Value

You can also filter data using numeric comparisons.

Base R

expensive_cars <- df[df$selling_price > 500000, ]

dplyr

cheap_cars_dplyr <- df %>%
  filter(selling_price < 500000)

Multiple Conditions

Base R

You can combine conditions using logical operators such as & for AND.

diesel_manual_cars <- df[df$fuel == "Diesel" & df$transmission == "Manual", ]

dplyr

You can pass multiple conditions to filter() function, separated by comma.

diesel_manual_cars_dplyr <- df %>%
  filter(fuel == "Diesel", transmission == "Manual")
question mark

nrow() is used to:

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  6

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  6
some-alt