Answers for "r mapply stack overflow"

0

r mapply stack overflow

#simulated data and column, row indexes
set.seed(100)
d <- data.frame(matrix(1:100,nrow=10,ncol=10))
y <- lapply(vector("list", 5),function(x){sample(1:10,5)}) 
x <- as.list(c(1,3,5,7,9),length=5)

# version in loop
whatiwant <- list(length=5)
for (i in 1:5){
   whatiwant[[i]] <- d[y[[i]],x[[i]]]
}

fun <- function(x,y,d){d[y,x]}

whatiwant2 <- mapply(fun,y,x,MoreArgs=d)
Posted by: Guest on May-01-2022

Browse Popular Code Answers by Language