Welcome to the seventh lesson in our Computational Statistics series.
In the R programming language, indexing and subsetting are critical techniques for data wrangling. Instead of manually altering large datasets, statisticians use logical vectors and coordinate-based indexing to programmatically extract, isolate, or modify specific elements within a vector, matrix, or data frame.
In this lecture, we explore how to manipulate data structures using logical operators (such as less than, greater than, equal to, and not equal to). We walk through the process of identifying missing values using the is.na() function, and how to use logical subsetting to instantly replace those missing values across an entire dataset.
We also cover:
Character Strings & Escape Sequences: How R handles text data, and how to format strings using escape sequences for newlines and tabs.
The Paste Function: How to concatenate strings and numbers together, including a solution to our previous programming challenge of creating a standard 52-card deck.
Numerical & Name Indexing: How to extract elements by their exact numerical position or by their assigned categorical names.
Data Frame Subsetting: How to use the comma operator within square brackets to isolate specific rows and columns in two-dimensional datasets like mtcars.
Data Coercion: How to force data structures into different types (such as converting text to numbers) using functions like as.numeric() and as.character().
► Watch the previous video in this series: • Database Management Systems & SQL | Comput...
► Watch the next video in this series: • Database Management Systems & SQL | Comput...
Don't forget to subscribe for more complete courses on mathematics and statistics.
TIMESTAMPS:
00:00:00 What are logical operators in R?
00:03:22 How to find missing values (NA vs NaN) in R?
00:07:29 How to use character strings and escape sequences?
00:14:12 How to concatenate strings using the paste function?
00:18:22 R Programming Challenge: Creating a Deck of Cards
00:22:37 How to index and subset data using logical vectors?
00:26:45 How to subset data using numerical indices?
00:30:38 How to index vectors by names or labels?
00:34:01 How to select specific rows and columns in a data frame?
00:38:16 How to modify and replace subsets of data?
00:44:13 How to use union (OR) and intersection (AND) logical operators?
00:46:39 How to exclude elements using negative indices?
00:48:56 How to coerce data types in R?
Support the Channel
All of my lectures are provided completely for free. If this video helped you understand a complex topic or prepare for an exam, you can buy me a coffee here: https://ko-fi.com/houstonwehaveaprobl...