What is sapply in R?

What is sapply in R?

What is sapply in R?

This recipe explains what is sapply in R

Recipe Objective

What is sapply in R? sapply function takes a vector as an input and provides output in a vector or matrix form. Syntax — **sapply (x,function)** x — input vector function — function which is to be applied on the input sapply () function is used instead of a for loop for iterating over a list or a vector. This recipe demonstrates an example using sapply function.

Step 1 - Create a vector

sapply(1:20,function(i) i + 5) #Using sapply()
"Output is": 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Step 2 - Create a list

Using sapply() on a list for calculating sum of the elements with sum function.

list1 <- list(a <- c(1,2,3,4,5)) sapply(list1,sum)
"Output is": 15 

Relevant Projects

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Image Segmentation using Mask R-CNN with Tensorflow
In this Deep Learning Project on Image Segmentation Python, you will learn how to implement the Mask R-CNN model for early fire detection.

Predict Employee Computer Access Needs in Python
Data Science Project in Python- Given his or her job role, predict employee access needs using amazon employee database.

Time Series Python Project using Greykite and Neural Prophet
In this time series project, you will forecast Walmart sales over time using the powerful, fast, and flexible time series forecasting library Greykite that helps automate time series problems.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.