My R skill is still at infancy and I am trying to loop over a calculation but I am not getting the right solution.
I want to perform the following operating 30 times
l1 = kak[dat1[[1]]$d1,dat1[[1]]$d2,tl] #1
l2 = kak[dat1[[2]]$d1,dat1[[2]]$d2,tl] #2
................................
l30 = kak[dat1[[30]]$d1,dat1[[30]]$d2,tl] #30
# then cbind each
cbind(l1,l2,...,l30)
In each case [[i]] must assume same value. Instead of doing it 30 times I decided to write a function which doesn't seem to work.
Here is function I tried writing:
dat1 <- split(dat,dat$group) ##group runs from 1:30
#dat has three column group, d1 and d2. d1 and d2 are numeric
nw <- 0
for(i in 1:length(dat1)){
# str(kak) num [1:360, 1:180, 1:830]
# str(tl) int [1:84] 754 ...
nw =kak[dat1[[i]]$d1,dat1[[i]]$d2,tl]
}
I tried searching for similar question here had no luck. Anyone with solution or an idea of an exiting thread that solved similar issue should kindly point me in the right direction.