What is mapply in R?

This recipe explains what is mapply in R

Recipe Objective

What is mapply in R? mapply () function is a multivariate type of sapply () function i.e mapply () accepts multiple arguments at a time. Syntax — **mapply (function,list)** function — a function like sum, etc is passed list — list of numbers on which the function will be applied This recipe demonstrates an example on mapply function..

Step 1 - Create a vector

a <- mapply(sum,1:10,1:10) # mapply sums up all the first elements, then second elements, and so on till the tenth elements. print(a)
"Output is ":  2  4  6  8 10 12 14 16 18 20 
a <- mapply(rep,1:10,10:1) # mapply repeats the first element 10 times, second element 9 times till the last element one time. print(a)
"Output is ": 
[[1]]
 [1] 1 1 1 1 1 1 1 1 1 1

[[2]]
[1] 2 2 2 2 2 2 2 2 2

[[3]]
[1] 3 3 3 3 3 3 3 3

[[4]]
[1] 4 4 4 4 4 4 4

[[5]]
[1] 5 5 5 5 5 5

[[6]]
[1] 6 6 6 6 6

[[7]]
[1] 7 7 7 7

[[8]]
[1] 8 8 8

[[9]]
[1] 9 9

[[10]]
[1] 10

What Users are saying..

profile image

Ameeruddin Mohammed

ETL (Abintio) developer at IBM
linkedin profile url

I come from a background in Marketing and Analytics and when I developed an interest in Machine Learning algorithms, I did multiple in-class courses from reputed institutions though I got good... Read More

Relevant Projects

Learn to Build a Polynomial Regression Model from Scratch
In this Machine Learning Regression project, you will learn to build a polynomial regression model to predict points scored by the sports team.

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.

Learn How to Build a Logistic Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple logistic regression model in PyTorch for customer churn prediction.

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

LLM Project to Build and Fine Tune a Large Language Model
In this LLM project for beginners, you will learn to build a knowledge-grounded chatbot using LLM's and learn how to fine tune it.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed

Deploy Transformer BART Model for Text summarization on GCP
Learn to Deploy a Machine Learning Model for the Abstractive Text Summarization on Google Cloud Platform (GCP)

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.