vendredi 2 juin 2017

looping a sample function through two lists in R

I have a two lists. list2 are the corresponding probabilities to use for list1 in order to sample the values for each index from list1.

For instance, the probability of selecting list[[1]][1] is 3.333333e-05 and the probability of selecting list[[1]][2] is 2.500000e-05. I would like to loop through this in a computational quick manner so that the output will be the position (not the value) of the most probable selection at each index. Also, the NA should be kept.

head(list1)
[[1]]
[1] 1 0

[[2]]
[1] 1

[[3]]
[1] 0

[[4]]
[1] NA

[[5]]
[1] 0

[[6]]
[1] 0 0 4

head(list2)
[[1]]
[1] 3.333333e-05 2.500000e-05

[[2]]
[1] 3.333333e-05

[[3]]
[1] 2.5e-05

[[4]]
[1] NA

[[5]]
[1] 2.5e-05

[[6]]
[1] 2.5e-05 2.5e-05 1e-04




Aucun commentaire:

Enregistrer un commentaire