Performing Operations on Multiple Lists simultaneously in R Programming – mapply() Function

mapply() function in R Language is used to perform mathematical operations on multiple lists simultaneously.

Syntax: mapply(func, list1, list2, …)

Parameters:
list1, list2, …: Created Lists
func: operation to be applied

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate 
# mapply() function 
    
# Creating a list 
A = list(c(1, 2, 3, 4)) 
    
# Creating another list 
B = list(c(2, 5, 1, 6)) 
    
# Applying mapply() 
result = mapply(sum, A, B) 
print(result) 

chevron_right


Output:

[1] 24

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate 
# mapply() function 
    
# Creating a list 
A = list(c(1, 2, 3, 4)) 
    
# Creating another list 
B = list(c(2, 5, 1, 6)) 
    
# Applying mapply() 
result = mapply(prod, A, B) 
print(result) 

chevron_right


Output:

[1] 1440
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.