You could solve the problem simply iterating a list of values and using the assign
function (assign a value to a name in an environment).
Try this reproducible code:
> set.seed(123)
> my_data <- as.data.frame(matrix(rnorm(3*50), nrow=50, ncol=3))
> values_list <- c("A","B","C")
> colnames(my_data) <- values_list
>
> for (v in values_list) {
+ assign(v, my_data[1:48, v])
+ }
> A
[1] -0.56047565 -0.23017749 1.55870831 0.07050839 0.12928774
[6] 1.71506499 0.46091621 -1.26506123 -0.68685285 -0.44566197
[11] 1.22408180 0.35981383 0.40077145 0.11068272 -0.55584113
[16] 1.78691314 0.49785048 -1.96661716 0.70135590 -0.47279141
[21] -1.06782371 -0.21797491 -1.02600445 -0.72889123 -0.62503927
[26] -1.68669331 0.83778704 0.15337312 -1.13813694 1.25381492
[31] 0.42646422 -0.29507148 0.89512566 0.87813349 0.82158108
[36] 0.68864025 0.55391765 -0.06191171 -0.30596266 -0.38047100
[41] -0.69470698 -0.20791728 -1.26539635 2.16895597 1.20796200
[46] -1.12310858 -0.40288484 -0.46665535
As showed, you can use the variable A
, B
, C
.