Uploaded February 2021 | Updated November 2026, 3 hours ago
This is lesson 24 of a 30-part introduction to the R programming language for data analysis and predictive modeling. Link to the code notebook below:
Intro to R: Hypothesis Testing
kaggle.com/hamelg/intro-to-r-part-24-Hypothesis-Testing
This lesson covers statistical hypothesis testing and the t-test. The t-test is a foundational statistical inference test that is the building block of many common data science techniques, such as A/B testing.
This guide does not assume any prior exposure to R, programming or data science. It is intended for beginners with an interest in data science and those who might know other programming languages and would like to learn R.
I will create the videos for this guide such that you should be able to learn a lot just watching on YouTube, but to get the most out of the guide, it is recommended that you create a Kaggle account so that you can fork and edit each lesson so that you can follow along and run code yourself.
Introduction to R Playlist:
youtube.com/playlist?list=PLiC1doDIe9rDjk9tSOIUZJU4s5NpEyYtE
This is lesson 24 of a 30-part introduction to the R programming language for data analysis and predictive modeling. Link to the code notebook below:
Intro to R: Hypothesis Testing
kaggle.com/hamelg/intro-to-r-part-24-Hypothesis-Testing
This lesson covers statistical hypothesis testing and the t-test. The t-test is a foundational statistical inference test that is the building block of many common data science techniques, such as A/B testing.
This guide does not assume any prior exposure to R, programming or data science. It is intended for beginners with an interest in data science and those who might know other programming languages and would like to learn R.
I will create the videos for this guide such that you should be able to learn a lot just watching on YouTube, but to get the most out of the guide, it is recommended that you create a Kaggle account so that you can fork and edit each lesson so that you can follow along and run code yourself.
Introduction to R Playlist:
youtube.com/playlist?list=PLiC1doDIe9rDjk9tSOIUZJU4s5NpEyYtE




![How to Get Unique (Distinct) Values of a Column in Pandas (Python)
↓ Code Available Below! ↓
This video shows how to check the unique or distinct values in a column of a pandas data frame. This can be useful to get an idea of the number of variety of values in a given column. The video also shows a method for checking all the combinations of values in two or more columns.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import pandas as pd
import statsmodels.api as sm #(To access mtcars dataset)
mtcars = sm.datasets.get_rdataset(mtcars, datasets, cache=True).data
mtcars.head()
# Get unique entries of a column with series.unique()
mtcars[cyl].unique()
# Get unique entries across multiple columns
mtcars_subset = mtcars[[cyl, gear]]
mtcars_subset.drop_duplicates().reset_index(drop=True)
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only How to Get Unique (Distinct) Values of a Column in Pandas (Python)](https://i.ytimg.com/vi/51yAgEDjaJI/mqdefault.jpg)
![How To Use Apply in R
The apply function lets you execute another function across a given dimension of a multidimensional data object like a data frame, matrix or array. It provides a quick way to run a function on every column or every row of a data frame, without having to write a custom for loop.
Code used in this code clip:
# Apply a function across the columns of a data frame
apply(X = mtcars, # data object
FUN = median, # function to apply
MARGIN = 2) # axis to apply to. 1 = rows, 2 = columns
# Apply a function across the rows of a data frame
stat_readout <- function(x){
return(paste(x[cyl], cylindar car with,
x[mpg], mpg, weighing, x[wt] * 1000, pounds.))
}
apply(X = mtcars, # data object
FUN = stat_readout, # function to apply
MARGIN = 1) # axis to apply to. 1 = rows, 2 = columns
# Function with additional arguments
stat_readout_custom <- function(x, args){
readout <- paste(x[cyl], cylindar car with)
for (stat in args){
readout <- paste(readout, and, x[stat], stat)
}
return(readout)
}
apply(X = mtcars, # data object
FUN = stat_readout_custom, # function to apply
MARGIN = 1, # axis to apply to
args = c(mpg, wt)) # additional arguments
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! For R that means I may use = for assignment and the special Unicode large < and > symbols in place of the standard sized ones for dplyr pipes and comparisons. These special symbols should work as expected for R code on Windows, but may need to be replaced with standard greater than and less than symbols for other operating systems. How To Use Apply in R](https://i.ytimg.com/vi/5lJX4IgmqRA/mqdefault.jpg)

![Python Regex: How To Replace All Substrings In a String
↓ Code Available Below! ↓
This video shows how to replace all substrings that match a given pattern with a different string using the regular expressions package in Python. Text data often contains errors or irregularities that need to be fixed prior to using it for other purposes. Finding and replacing substring within text is a common preprocessing task when working with text. The re.sub() function allows you to replace substrings based on a regex patterns, allowing for efficient replacement of multiple substrings at the same time.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import re
lines = Nappa - What does the scouter say about his power level?
Vegeta - Its over 9000!
Nappa - What 9000? That cant be right. Can it?
# Use re.sub() to find and replace substrings
new_lines = re.sub(pattern = [0-9]+,
repl = 8000,
string = lines)
print(new_lines)
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only Python Regex: How To Replace All Substrings In a String](https://i.ytimg.com/vi/5ofcaxkMv5U/mqdefault.jpg)


![How To Add a Column to a Data Frame in Pandas (Python)
This video shows 3 ways to add new columns to Pandas Data Frames in Python. Adding new columns is a basic data manipulation task that is a common part of the data cleaning and wrangling process.
If you find this video useful, like, share and subscribe to support the channel!
► Subscribe: https://www.youtube.com/c/DataDaft?sub_confirmation=1
Code used in this Python Code Clip:
import pandas as pd
import statsmodels.api as sm #(To access mtcars dataset)
mtcars = sm.datasets.get_rdataset(mtcars, datasets, cache=True).data
mtcars.head()
# Method #1: Direct Column Assignment
mtcars[new_1] = mtcars.mpg > 20
mtcars.head()
# Method #2: Use .insert()
mtcars.insert(2, # Where to insert
new_2, # Name of new column
mtcars.mpg > 25) # What to insert
mtcars.head()
# Method #3: Use .assign()
mtcars = mtcars.assign(new_3 = mtcars.mpg > 15, # New column
new_4 = mtcars.mpg > 30) # Another new column
mtcars.head()
* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .
⭐ Kite is a free AI-powered coding assistant that integrates with popular editors and IDEs to give you smart code completions and docs while you’re typing. It is a cool application of machine learning that can also help you code faster! Check it out here: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=datadaft&utm_content=description-only How To Add a Column to a Data Frame in Pandas (Python)](https://i.ytimg.com/vi/6WmNmAdX5wU/mqdefault.jpg)