using nested lapply
lapply(my_list, function(x) lapply(x, function(x) ifelse(length(x) == 0, 0, x)))
$`0`
$`0`$item1
[1] 0
$`0`$item2
[1] 350
$`0`$item3
[1] 0
$`1`
$`1`$item1
[1] 0
$`1`$item2
[1] 56
$`1`$item3
[1] 0
or sapply
inside lapply
lapply(my_list, function(x) sapply(x, function(x) ifelse(length(x) == 0, 0, x)))
$`0`
item1 item2 item3
0 350 0
$`1`
item1 item2 item3
0 56 0
or using sapply
both inside & outside
sapply(my_list, function(x) sapply(x, function(x) ifelse(length(x) == 0, 0, x)))
0 1
item1 0 0
item2 350 56
item3 0 0
on the list
my_list <- list(`0` = list(item1 = numeric(0), item2 = 350, item3 = numeric(0)),
`1` = list(item1 = numeric(0), item2 = 56, item3 = numeric(0)))