3
Hi, I have a data.frame (df) 8 rows x 8 columns. I am calling the columns "ST[i]".
df <- structure(list(ST1 = c(58.69, 58.5, 58.5, 58.69, 58.69,
58.5, 58.69, 58.69), ST2 = c(68.7, 68.42, 68.42, 68.7,
68.7, 68.42, 68.7, 68.7), ST3 = c(69.15, 69.15, 68.83,
69.15, 69.15, 69.15, 69.15, 69.15), ST4 = c(78.99,
80.29, 78.99, 77.7, 78.99, 80.29, 78.99, 77.7), ST5 = c(75.65,
75.65, 75.65, 72.57, 71.07, 68.14, 66.7, 66.7), ST6 = c(71.35,
71.35, 79.83, 86.38, 83.09, 87.49, 87.49, 78.76), ST7 = c(73.61,
72.48, 78.22, 102.06, 82.33, 79.97, 112.48, 91.39), ST8 = c(77.57,
77.57, 77.57, 77.57, 77.57, 77.57, 77.57, 79.17)), .Names = c("ST1",
"ST2", "ST3", "ST4", "ST5", "ST6", "ST7", "ST8"), row.names = 122:129, class = "data.frame")
I need to execute a command waveslim::mra()
for each of these columns.
The result of this command, for each column, will be a list with 12 vectors. Therefore, the final product will be 8 lists, each list with 12 vectors.
I can do, for example:
dwc_ST1 <- mra(ST1, wf = "la8", method = "dwt", J=3, boundary = "reflection"
dwc_ST2 <- mra(ST2, wf = "la8", method = "dwt", J=3, boundary = "reflection")
...
dwc_ST8 <- mra(ST8, wf = "la8", method = "dwt", J=3, boundary = "reflection")
But it would be really nice if you simplified that. I thought about for()
, in something like:
names_dwc <- as.character(rep(NA, ncol(df)))
for (k in 1:ncol(df)){
names[k] <- paste('dwc_ST', k, sep = "")
dwc_ST[k] <- mra(df[ ,k], wf = "la8", method = "dwt", J=3, boundary = "reflection")
}
But it has appeared:
Error in ST[k] <- mra(df,[ , k], wf = "la8", : Object 'dwc_ST' not found
I thought I would have solved this problem by creating these 8 ST’s, with the line (I used above):
Names[k] <- Paste('dwc_ST', k, Sep = "")
I don’t seem to know how to create the files to generate the results. Someone can help me?
What is the expected result? Would it be 8 lists with 11 or 12 vectors or 1 list with 88 or 96 vectors? Also, it would be good for you to provide your data set, or a part of it (use the command
dput
), for your problem to be reproducible. Finally, when using functions that are not part of theR base
, indicate at the beginning of your code which package is needed– Rafael Cunha
Okay, thanks for the instructions, man.
– Rafael-Pedrollo-de-Paes
The product will be 8 lists (one for each column) with 12 vectors each list. Total: 96 vectors. mra() is from the "waveslim" package. Anyway, the data.frame has 2048 lines. Using dput() I am pasting the first 8 lines.
– Rafael-Pedrollo-de-Paes
To make it easier, put the result of
dput
in your question.– Rafael Cunha
Rafael, I followed your instructions, deleted my comments and explained better in the question above. My original data have 2048 lines. I adapted to 8 lines.
– Rafael-Pedrollo-de-Paes