これは@joranのコメントに基づく解決策です
> set.seed(1) # for reproducibility
> # the following does the same as your `for` loop and returned value is a list
> Season.list <- replicate(10, rnorm(10, 0, 1), simplify=FALSE)
> # giving some names
> names(Season.list) <- paste0("Season", 1:length(Season.list))
> # setting first element to 1
> Season.list <- lapply(Season.list, function(x) {x[1] <- 0; x})
> list2env(Season.list, envir = .GlobalEnv) # will give you each `Season` as you want :D
また、それを行う別の方法として、
> set.seed(1)
> Season <- replicate(10, rnorm(10, 0, 1)) # the returned object is a matrix
> colnames(Season) <- paste0("Season", 1:ncol(Season))
> Season[1,] <- 0
それぞれのベクトルが必要な場合はSeason
、使用しますattach
(良い考えではありません)
> attach(as.data.frame(Season))
> Season1
[1] 0.0000000 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684 0.4874291 0.7383247 0.5757814 -0.3053884
> Season2
[1] 0.00000000 0.38984324 -0.62124058 -2.21469989 1.12493092 -0.04493361 -0.01619026 0.94383621 0.82122120
[10] 0.59390132