How to make a new data frame automatically from variables of another data frame in R?

17 views Asked by At

I have a data table with 3 variables (It is just an example):

DT <- data.table (A=c(1,1,1,2,2,3,3,4,4,4,5), B=c(200,210,300,420,289,365,587,250,110,500,800), C=c(0.6,0.35,0.6,0.85,0.22,0.36,0.39,0.31,0.33,0.58,0.66))

I have split DT based on A

DT_Split <- split(DT, DT$A)

So, the output is:

$`1`
   A   B    C
1: 1 200 0.60
2: 1 210 0.35
3: 1 300 0.60

$`2`
   A   B    C
1: 2 420 0.85
2: 2 289 0.22

$`3`
   A   B    C
1: 3 365 0.36
2: 3 587 0.39

$`4`
   A   B    C
1: 4 250 0.31
2: 4 110 0.33
3: 4 500 0.58

$`5`
   A   B    C
1: 5 800 0.66

I can make new data tables from every data table that I have in DT_Split:

A<- DT_Split$`1`
B<- DT_Split$`2`
C<- DT_Split$`3`
D<- DT_Split$`4`
E<- DT_Split$`5`

But my question is: Is it possible to do this automatically? Is it possible to make new data tables with defined names for every data table in DT_Split automatically instead of doing [A<- DT_Split$1 ... E<- DT_Split$5] ?

I would appreciate if you could give me some idea. Thanks

0

There are 0 answers