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

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

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.

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.

Digit Recognition using CNN for MNIST Dataset in Python
In this deep learning project, you will build a convolutional neural network using MNIST dataset for handwritten digit recognition.

Time Series Analysis with Facebook Prophet Python and Cesium
Time Series Analysis Project - Use the Facebook Prophet and Cesium Open Source Library for Time Series Forecasting in Python

OpenCV Project to Master Advanced Computer Vision Concepts
In this OpenCV project, you will learn to implement advanced computer vision concepts and algorithms in OpenCV library using Python.

Multilabel Classification Project for Predicting Shipment Modes
Multilabel Classification Project to build a machine learning model that predicts the appropriate mode of transport for each shipment, using a transport dataset with 2000 unique products. The project explores and compares four different approaches to multilabel classification, including naive independent models, classifier chains, natively multilabel models, and multilabel to multiclass approaches.

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

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.

End-to-End Speech Emotion Recognition Project using ANN
Speech Emotion Recognition using RAVDESS Audio Dataset - Build an Artificial Neural Network Model to Classify Audio Data into various Emotions like Sad, Happy, Angry, and Neutral