Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate mean value of two list for each row

Tags:

r

I have two lists as below:

l1 <- list(a=1, b=2, c=3)
l2 <- list(a=4, b=5, c=6)

I want to calculate the mean value of the two lists for each row and assign the result to a new list. Like below:

l3 <- mean(l1, l2)

How can I achieve this in R?

like image 911
Joey Yi Zhao Avatar asked Nov 28 '25 11:11

Joey Yi Zhao


1 Answers

Using:

colMeans(do.call(rbind.data.frame, list(l1,l2)))

gives:

  a   b   c 
2.5 3.5 4.5 
like image 77
Jaap Avatar answered Dec 01 '25 00:12

Jaap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!