'"more elements supplied than there are to replace" when trying to generate date in columns R
Hello i have run into a problem when trying to itreate a functionm and organizing them into colmuns. Basically i want to create a dataset of fake stocks:
[][v1] [v2] [v3] [v4] [v5]
[1]
[2]
[3]
[4]
[5]
However when i it i get the error: "Error in stock_gen[[i]] <- as.matrix(rtsplot.fake.stock.data(n, y0 = 10, : more elements supplied than there are to replace" here is my code:
library("rtsplot")
i = 5
n = 5
stock_gen <- matrix(ncol = n, nrow = i)
for(i in stock_gen){
stock_gen[[i]] <-
as.matrix(rtsplot.fake.stock.data(
n,
y0 = 10,
stdev = 0.1,
ohlc = FALSE,
method = c("normal", "adhoc"),
period = c("day", "minute"),
remove.non.trading = FALSE
))}
Solution 1:[1]
If it doesn't have to be a matrix (and even then you can easily convert back from dataframe to matrix), here's one possible blueprint:
library(rtsplot)
i = 5 ## row count
n = 5 ## column count
stock_gen <-
as.data.frame(
structure(lapply(1:n, function(x){
rtsplot.fake.stock.data(n = i,
y0 = 10 ##, other arguments ...
)
}
),
names = paste0('series_',LETTERS[1:5]))
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
