Avoid using loops through application - is there a problem?

I wrote Rscript to bring some data in the right format. In particular, I just want to rearrange the data set to finally get it in the format of 8 rows and 12 columns (96-well plate). I have nested two loops that work great:

element1 = seq(1,96,1)
element2 = seq(0.5,48,0.5)
df = data.frame(element1,element2)
storage = data.frame(matrix(NA,nrow = 8, ncol = 12))
container = vector("list",ncol(df))

for (n in 1:ncol(df)){
      j = 0  
        for (i in seq(1,length(df[,n]),12)) { 
              j = j+1
              storage[j,] = df[(i):(i+11),n]  
          }
     container[[n]]=storage

}

Note: I have packed the data into a list to simplify exporting to .xls.
And I know that this is a really simple approach ... but it works

, , :-), , "" . . , . ? , ?

,

+4
1

, .

container <- lapply(df, matrix, byrow=T, ncol=12)

data.frame,

container <- lapply(df, function(x) data.frame(matrix(x, byrow=T, ncol=12)))
+7

Source: https://habr.com/ru/post/1568925/


All Articles