Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Data Selection - Basics | Data Manipulation and Cleaning
Data Analysis with R

bookData Selection - Basics

Once your dataset is loaded into R, you need to learn how to work with specific parts of it. This means selecting particular rows and columns that you want to focus on. Whether you're cleaning data or analyzing specific trends, being able to subset your data efficiently is essential.

Loading Your Dataset

Before working with any data, it needs to be loaded and viewed:

library(tidyverse) # load the tidyverse package
df <- read_csv("car_details.csv")  # read the dataset
View(df) # open the dataset in a spreadsheet-style viewer

Selecting Rows

  • Use numeric indexing to select rows by position;
  • In R, indexing starts from 1;
  • For example, df[3, ] selects the third row from the dataset.
df[3, ]

Selecting specific columns

  • Use numeric indexing to select a column by its position;

  • For example, df[, 5] selects the fifth column from the dataset;

  • Leave the row position blank to select all rows.

df[, 5]

Selecting a column by name

  • Use the $ operator to access a column by its name;

  • This is a quick and readable way to extract a single column;

  • For example, df$km_driven selects the column named km_driven.

view(df$km_driven)
question mark

Which symbol is used to access a column by name in base R?

Select the correct answer

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 4

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Suggested prompts:

Can you explain the difference between base R and dplyr for data selection?

How do I select multiple rows or columns at once?

What should I do if I get an error when trying to select a row or column?

Awesome!

Completion rate improved to 4

bookData Selection - Basics

Scorri per mostrare il menu

Once your dataset is loaded into R, you need to learn how to work with specific parts of it. This means selecting particular rows and columns that you want to focus on. Whether you're cleaning data or analyzing specific trends, being able to subset your data efficiently is essential.

Loading Your Dataset

Before working with any data, it needs to be loaded and viewed:

library(tidyverse) # load the tidyverse package
df <- read_csv("car_details.csv")  # read the dataset
View(df) # open the dataset in a spreadsheet-style viewer

Selecting Rows

  • Use numeric indexing to select rows by position;
  • In R, indexing starts from 1;
  • For example, df[3, ] selects the third row from the dataset.
df[3, ]

Selecting specific columns

  • Use numeric indexing to select a column by its position;

  • For example, df[, 5] selects the fifth column from the dataset;

  • Leave the row position blank to select all rows.

df[, 5]

Selecting a column by name

  • Use the $ operator to access a column by its name;

  • This is a quick and readable way to extract a single column;

  • For example, df$km_driven selects the column named km_driven.

view(df$km_driven)
question mark

Which symbol is used to access a column by name in base R?

Select the correct answer

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 4
some-alt