What do I want to do: I have a data frame where the first columns are wired, and the remaining columns are numeric values Applying different factors in the filled rows, I want to add the first three rows in the three lines in the group of three, such as line 1 * x + line 4 * y, line 1 * x + row 5 * y, line 1 * X + row 6 * y, then row 2 * x + line 4 * y, and so on A row3 * x + row6 * y then i want to do the same thing again, but with different values for x and y, and then for the x and y, with the different values the third time. Then I want to do the same with 1-3 and 7-9 lines, then with 1-3 and 10-12 The correct sequence is important. I want to write all this in the form of rows in a new data frame.
I also want to add the related strings of the first column, add a marker so that I know which Circulation is done, and then a counter per counter counter. I want to add it to my data frame results, so I can see which row has come from
What do I have to do: After extensive magic with the loops, this code is finally what I want That does, but it's ugly, and it's slow to slow with my actual data (the actual data frame has 1762 columns).
numbers & lt; - data.frame (repeat (10, sample (1: 100,12, delegate = TRUE))) ID & lt; - data.frame (id = c ("d1", "D2", "D3", "v11", "v12", "v13", "v21", "v22", "v23", "v31" , "V32", "v33")) & lt; - cbind (ID, number) result & lt; - data.frame () data.raw & lt; - Data [, - 1] Story & lt; - data.frame () q = 1 ################### Lines with 1-3 rows 4-6 k = 1 # for my constant counter (1: 3 i) {for (4: 6 in j) {Results & lt; Legend [Q1] & lt; - Paste (data [i, 1], data [j, rbind (result, 0.99 * (data; raw [i,]) + 0.01 * 1], "01", k, sep = "_") q = q + 1 k = k + 1}} for k = 1 (i in 1: 3) {for (j in 4: 6) {result & Lt; - Legend [Q1] <- Paste (data [i, 1], data [ja, rbid id (result, 0.95 * (data. Raw [i,]) + 0.05 * (data. [Ja]] 1], "05", k, sep = "_") q = q + 1 k = k + 1}} for k = 1 (i (1: 3)) {for (in j 4: 6) {Results [1] & lt; - Paste (data [i, 1], results & lt; - rbind (result, 0.9 * (data.raw [i,]) + 0.1 * (data. Raw [ Ja]] Legend [q, 1] data [j, 1], "10", k, sep = "_") q = q + 1 k = k + 1}} #################### For lines 7-9 k = 1 with 1-3 rows (i in 1: 3) {for (j at 7: 9) ) (Results [1] & lt; - Paste (data [i, 1] (results, 19.9 * (data. Draw [i,]) + 0.01 * (data. And [j,]) Legend [Q (I, 1), "01", k, sep = "_") q = q + 1 k = k + 1}} k = 1 (1: 3) for (1: 3) I: 9) {Results & lt; - rbind (Results, 0.95 * (data. Raw [i,]) + 0.05 * (data. Raw [J,]) Legend [Q1]
What do I have to do: It is possible for some beautiful, short, and sharply to take the place with loops, but where I am lost here I feel that I < Code> applicable Could use some improvement, but I am not able to fully understand the concept yet work, and then it gets more complicated all the descriptive wires.
Can anyone tell me in the right direction?
As the first step, instead of working with the data frame, simply convert them to matrix
Results Results & lt; -c () data. Raw & lt; - as.matrix (data [, - 1]) at the top
It should be sharpened.