a,b and c are list.
a<-list(c(6,5,7),c(1,2),c(1,3,4))
b<-list(c(1,2,3),c(4,5),c(6,7,8))
c<-list(1,2,2)
I want to replace "a" with "b" at place "c" to generate a new list.
The expected result is as follows:
[[1]]
[1] 1 5 7
[[2]]
[1] 1 5
[[3]]
[1] 1 7 4
Thank you for help!
Sounds like you're looking for Map
to iterate over all the lists simultaneously.
Map(function(a,b,c) {a[c]<-b[c]; a},a,b,c)
# [[1]]
# [1] 1 5 7
#
# [[2]]
# [1] 1 5
#
# [[3]]
# [1] 1 7 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With