Selçuk Korkmaz, PhD Profile picture
Apr 25 10 tweets 5 min read Twitter logo Read on Twitter
🧵 1/10 🧵
🎯 Demystifying the #Apply Functions Family in #R 🎯

Are you an #Rstats enthusiast? Let's dive into the powerful 'apply' family of functions to help you manipulate and analyze data efficiently! 👩‍💻👨‍💻

#DataScience #RStats Source: https://r-coder.com...
🧵 2/10
Meet the Family! 🏡

There are six main functions in the 'apply' family:

1️⃣ apply()
2️⃣ lapply()
3️⃣ sapply()
4️⃣ vapply()
5️⃣ mapply()
6️⃣ tapply()

Each has its own use case and is designed to work with different data structures. Let's explore them! 🕵️‍♂️🔍

#RStats
🧵 3/10 🧵
1️⃣ apply()

Use apply() for applying a function across the rows or columns of a matrix or array.

Syntax: apply(X, MARGIN, FUN, ...)

X: array or matrix
MARGIN: 1 for rows, 2 for columns
FUN: function to apply
... : additional arguments

#RStats #DataScience
🧵 4/10 🧵
2️⃣ lapply()

Use lapply() for applying a function to each element of a list or vector and returning a list.

Syntax: lapply(X, FUN, ...)

X: list or vector
FUN: function to apply
... : additional arguments

#Rstats #DataScience
🧵 5/10 🧵
3️⃣ sapply()

sapply() is a simplified version of lapply(), returning a vector or matrix instead of a list.

Syntax: sapply(X, FUN, ..., simplify = TRUE)

X: list or vector
FUN: function to apply
... : additional arguments
simplify: to return a vector/matrix

#RStats
🧵 6/10 🧵
4️⃣ vapply()

vapply() is a safer and more rigid version of sapply(). It requires you to specify the output type and length, ensuring consistency.

Syntax: vapply(X, FUN, FUN.VALUE, ..., USE.NAMES = TRUE)

FUN.VALUE: output type
USE.NAMES: keep names or not

#RStats
🧵 7/10 🧵
5️⃣ mapply()

mapply() is a multivariate version of sapply(). It applies a function to multiple input lists or vectors, element-wise.

Syntax: mapply(FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE)

MoreArgs: additional args
USE.NAMES: keep names or not
🧵 8/10 🧵
6️⃣ tapply()

tapply() is great for applying a function to subsets of a vector, as defined by factors.

Syntax: tapply(X, INDEX, FUN, ..., simplify = TRUE)

X: vector
INDEX: list of factors
FUN: function to apply
... : additional args
simplify: return vector/matrix
🧵 9/10 🧵
🔁 When to Use Which Function?

1️⃣ apply(): use with matrices/arrays for row/column operations
2️⃣ lapply(): use with lists/vectors, get a list output
3️⃣ sapply(): use with lists/vectors, get a vector/matrix output
10/10 🧵

4️⃣ vapply(): use with lists/vectors, enforce output type
5️⃣ mapply(): use with multiple lists/vectors
6️⃣ tapply(): use with vector subsets defined by factors

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Selçuk Korkmaz, PhD

Selçuk Korkmaz, PhD Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @selcukorkmaz

Apr 26
[1/8] 📚 Introducing #Quarto: A Versatile, New and Exciting Publishing Tool! 🌟
Quarto is a powerful, open-source, and user-friendly publishing framework that streamlines the process of creating beautiful books, documents, and websites. Let’s explore it now!
#RStats #DataScience Image
[2/8] 🤓 Language Agnostic: Quarto works seamlessly with multiple languages, including #Markdown, #LaTeX, #RMarkdown, and #Jupyter notebooks. So, whether you're a researcher or a creative writer, Quarto has you covered! 🌍
#DataScience #RStats
[3/8] 🔁 Format Flexibility: With Quarto, you can convert your content into various formats, such as PDF, HTML, EPUB, and even slide presentations. It makes sharing your work with diverse audiences a breeze! 🌬️
#RStats #DataScience
Read 8 tweets
Apr 26
🧵1/9 A deep dive into the history of #Backpropagation: A key technique in training multilayer architectures for neural networks. This powerful method revolutionized the way we train AI systems, leading to major breakthroughs in various domains. 🤖#DataScience #DeepLearning #AI Source: https://www.youtube...
🧵2/9 #Backpropagation is based on a simple concept: use gradient descent to optimize multilayer networks. By applying the chain rule for derivatives, it computes gradients efficiently, leading to optimized weight configurations in each layer of the network. #DataScience #AI
🧵3/9 The shift to Rectified Linear Units (ReLU) accelerated learning in deep networks, allowing training without unsupervised pre-training. This non-linear activation function proved more effective than its smoother predecessors like tanh(z) or 1/(1+exp(−z)). #ReLU #DataScience
Read 10 tweets
Apr 26
🧵1/8 Loading datasets from various sources is crucial for data analysis. In this thread, we'll explore how to read datasets from different sources and software using R! 📚 #RStats #DataScience Image
🧵2/8 CSV Files: The "read.csv" function is a go-to for reading comma-separated values files. For improved performance and more flexibility, consider using the "read_csv" function from the readr package or the fread function from the data.table package. 📃 #CSV #RStats
🧵3/8 Excel Files: The readxl package provides functions like "read_excel" for reading data from Excel files (.xls and .xlsx). Alternatively, the openxlsx package offers more features, including reading and writing Excel files. 📊 #Excel #RStats
Read 9 tweets
Apr 25
Thread: (1/9) You might have heard the term 'bootstrapping' thrown around in discussions about statistics, data analysis, or machine learning. But what does it mean, and why is it so powerful? Let's break it down in simple terms! #RStats #DataScience Source: https://mlcourse.ai...
(2/9) Bootstrapping is a resampling technique that involves taking multiple samples from the original dataset, each time with replacement. It's like drawing marbles from a bag, putting each one back after recording its color. This helps us understand the uncertainty in our data.
(3/9) In real-life situations, it's not always feasible to collect more data. Bootstrapping allows us to make the most of what we have, creating a 'pseudo-replica' of our dataset through resampling. This helps us understand the variability of our estimates. #RStats #DataScience
Read 9 tweets
Apr 24
1/ 🎯 Introduction 📌
The #caret package in #R is a powerful tool for data pre-processing, feature selection, and machine learning model training. In this thread, we'll explore some useful tips & tricks to help you get the most out of caret. #DataScience #MachineLearning #RStats Image
2/ 🧹 Data Pre-processing 📌
caret offers various data pre-processing techniques, like centering, scaling, and removing near-zero-variance predictors. Use the preProcess() function to apply these methods before model training.🧪 #RStats #DataScience
3/ ⚙️ Feature Selection 📌
Use the rfe() function for recursive feature elimination. This method helps you find the most important features in your dataset, improving model performance & interpretation.🌟 #RStats #DataScience
Read 8 tweets
Apr 24
1/🧶📝 Welcome to a Twitter thread discussing the pros & cons of the #R packages, #knitr and #sweave. These packages allow us to create dynamic, reproducible documents that integrate text, code, and results. Let's dive into the strengths and weaknesses of each. #Rstats
2/🔍 #knitr is a more recent and widely-used package that simplifies the creation of dynamic reports. It's an evolution of #sweave and supports various output formats, including PDF, HTML, and Word. Plus, it's compatible with Markdown and LaTeX! #Rstats
3/🌟 Pros of #knitr:
✅ Better syntax highlighting
✅ Cache system to speed up compilation
✅ Inline code chunks
✅ Flexible output hooks
✅ More output formats
✅ Integrates with other languages
Overall, it provides more control and customization in document creation. #RStats
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(