[R] Store elements in a list in a triple for loop
katarv
katiasmirn at gmail.com
Sat Jul 23 03:10:01 CEST 2011
Hi,
I have a triple loop that goes through all elements of a list
Lst[[k]][[i,j]] and I want to pick only elements of Lst[[k]][[i,j]] > 0.4
or any value. Then I want to store the values of Lst[[k]][[i,j]] together
with their i,j,k values in another list. Say I have Lst[[2]][[4,7]] = 0.6, I
want to store it as a row
[,1] [,2] [,3], [,4]
2 4 7 0.6
I tried using VoxCorr <- list() and then inside the loop
VoxCorr[i,i,k] <- list(matrix = matrix (c(k,i ,j,
Lst[[k]][[i,j]]), nrow = 1, ncol = 4))
Which gives an error. It should be something pretty simple but I don't know
en exact syntax I could use to do it.
Thanks,
Here is the full loop code:
VoxCorr <- list()
for (i in 1:ncol(aaN))
{
for (j in 1:ncol(bbN))
{
for (k in 1:Nlags)
{
if ( Lst[[k]][[i,j]] >=CorrMin || Lst[[k]][[i,j]]
<=CorrMin )
{
VoxCorr[i,i,k] <- list(matrix = matrix (c(k,i ,j,
Lst[[k]][[i,j]]), nrow = 1, ncol = 4))
}
}
}
}
return (VoxCorr)
--
View this message in context: http://r.789695.n4.nabble.com/Store-elements-in-a-list-in-a-triple-for-loop-tp3688210p3688210.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list