Camford Oxbridge
Camford Oxbridge

Reputation: 894

How to subtract lists constructed same length vectors

I simplified as follows:

 list( 
      v = c(11,12,13),
      vv= c(21,22,23)
        ) 

 -list(W = c(1,2,3),
       WW= c(1,2,3)
       )

MY desired out put is

list(c(10,10,10),c(20,20,20))

My idea is for sentence or unlist().

Upvotes: 0

Views: 39

Answers (1)

Julius Vainora
Julius Vainora

Reputation: 48201

For this you could use Map:

Map(`-`, l1, l2)
# $v
# [1] 10 10 10
#
# $vv
# [1] 20 20 20

where

l1 <- list(v = c(11, 12, 13), vv = c(21, 22, 23)) 
l2 <- list(v = c(1, 2, 3), vv = c(1, 2, 3))

Upvotes: 2

Related Questions