I have these 2 nested lists wherein in each sublist, the length of its elements have different sizes.
list1<-list(
list(c(1,2,3), c(4,5,6),c(7,8,9)),
list(c(2,4,6), c(8,10,12),c(14,16,18))
)
list2 <- list(
list(c(1,0), c(1,2,0),c(1,2,3,0)),
list(c(1,0), c(1,2,0),c(1,2,3,0))
)
I would like to get the product of these two lists where the length of elements of each sublist follows the length of the sublist of list 2. Just like this:
output<-list(
list(c(1,0), c(4,10,0),c(7,16,27,0)),
list(c(2,0), c(8,20,0),c(14,32,54,0))
)
then, I want to find the sum of each sublist as a final output:
finaloutput<- list(
list(c(1), c(14),c(50)),
list(c(2), c(28),c(100))
)
I tried to multiply the two lists but it is giving me this error
Error in list1 * list2 : non-numeric argument to binary operator
Thank you very much for your help!
min is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.