I have these two list generated from a data.table
object and I would like to apply a function over them.
The lists look similar to this:
>list1
$AA
C
1: 0.07519183
$BB
C
1: 0.7174377
$CC
C
1: 0.1620897
$DD
C
1: 0.184746
>list2
$AA
P1 P2 P3 P4 P5 P6
1: 0.04770305 0.1624142 0.2899578 0.029753 0.1070376 0.17549
$BB
P1 P2 P3 P4 P5 P6
1: 0.7174377 0.5965736 0.2561482 0.2561482 0.2561482 0.1997866
$CC
P1 P2 P3 P4 P5 P6
1: 0.0317663 0.139877 0.139877 0.05305057 0.1620897 0.2189595
$DD
P1 P2 P3 P4 P5 P6
1: 0.184746 0.4246214 0.2704228 0.1070376 0.3215871 0.1519672
The function that I would like to apply is the following:
fun <- function(x,y){(sum(x>=y)+1)/(length(y)+1)}
I've tried:
new.list <- mapply(fun, list1, list2)
but it gives an error: >= only defined for equally-sized data frames
. I could repeat the values in list1
to avoid this error but is there another way?