How to get the list of available data frames in R environment?

R ProgrammingServer Side ProgrammingProgramming

When we perform any type of data analysis, there are many types of objects that are created in the R environment such as vector, data frame, matrix, lists, arrays, etc. If we want to get the list of available data frames in R environment then we can use the below command −

names(which(unlist(eapply(.GlobalEnv,is.data.frame))))

Example

 Live Demo

x1<-rnorm(25)
x1

Output

 [1]  0.567169417  0.225760338  0.431393591 -0.419678291 -2.167417490
 [6]  0.599410253 -1.936957284 -0.601723252 -0.210805670 -0.515634650
[11] -0.145867403 -1.670541518 -0.160427082  0.784548090 -0.530931156
[16]  0.973887609 -0.115687083 -1.469525241  0.903437248  0.260271889
[21] -1.021167526  0.261825724 -1.431022651  0.006119475 -0.935248330

Example

 Live Demo

x2<-data.frame(x=rpois(20,2),y=rpois(20,2))
x2

Output

   x  y
1  2  4
2  1  1
3  2  2
4  1  4
5  5  1
6  1  2
7  3  2
8  1  3
9  3  3
10 5  1
11 3  1
12 0  1
13 2  5
14 4  2
15 3  0
16 6  0
17 3  4
18 5  1
19 1  3
20 1  0

Example

 Live Demo

x3<-data.frame(x=rexp(20,2.1),y=rexp(20,1.2))
x3

Output

         x        y
1  0.08637793   0.3611441
2  0.06233789   1.0206873
3  1.20495802   0.6067851
4  0.60393345   0.1692306
5  0.11447822   0.4875182
6  0.32097787   0.2984741
7  0.09996313   0.7241003
8  0.52471669   1.2555738
9  0.69409516   0.2025357
10 0.08056040   0.8985850
11 0.27020003   1.6472922
12 0.18115211   0.6072404
13 1.12247247   0.0400686
14 0.02473768   2.3088929
15 0.09295997   1.2731939
16 2.02997989   1.3905549
17 1.76667321   0.3793563
18 0.44163965   0.1276282
19 0.08554350   0.5680570
20 0.90013924   1.1731834

Example

 Live Demo

x4<-runif(50,2,10)
x4

Output

 [1] 6.229683 2.848786 5.127299 6.074733 9.235342 7.086393 3.456571 6.476437
 [9] 9.180637 8.562265 3.642606 8.963444 2.665767 3.219165 2.455509 4.746601
[17] 5.700686 8.568766 2.106431 4.427528 7.566335 5.767371 9.606190 8.720031
[25] 9.161196 3.994676 6.623008 3.227018 4.013676 8.920018 8.652831 7.510169
[33] 8.799055 6.243303 5.223534 6.640771 3.359809 4.675036 5.699510 9.801201
[41] 9.237743 9.530666 4.077065 2.704086 7.189221 5.890195 4.968044 4.638300
[49] 5.019257 7.183788

Example

 Live Demo

x5<-sample(round(rnorm(5),2),50,replace=TRUE)
x5

Output 

 [1] -0.67 1.43 -0.67  0.79  1.62 1.62  1.43  1.62 0.79 -0.65 0.79  1.62
[13]  1.62 1.43  1.43  1.62 -0.67 1.62 -0.65  1.62 -0.67 0.79 1.62  0.79
[25]  1.62 1.43 -0.67  1.43 -0.67 1.43  1.43 -0.67 -0.65 1.43 1.62  1.43
[37]  1.62 1.43  1.62 -0.65  0.79 1.43  1.62  1.62 -0.65 1.43 1.62 -0.65
[49]  1.62 1.43

Example

 Live Demo

x6<-sample(round(rnorm(5,30,2.24),2),100,replace=TRUE)
x6

Output

 [1] 30.42 29.02 30.42 29.48 29.48 27.21 27.21 32.75 29.48 30.42 29.02 27.21
[13] 29.48 32.75 29.02 27.21 29.48 29.48 30.42 29.02 29.48 30.42 27.21 27.21
[25] 32.75 27.21 29.02 27.21 32.75 30.42 29.48 30.42 32.75 32.75 29.48 32.75
[37] 27.21 30.42 29.02 29.48 27.21 30.42 32.75 27.21 29.02 32.75 29.48 32.75
[49] 32.75 27.21 32.75 32.75 29.48 29.48 27.21 29.48 29.48 27.21 29.02 32.75
[61] 32.75 30.42 29.02 30.42 27.21 27.21 29.48 29.48 29.48 30.42 32.75 29.02
[73] 29.02 29.48 27.21 30.42 30.42 29.02 32.75 27.21 27.21 27.21 32.75 29.48
[85] 29.02 30.42 32.75 27.21 30.42 27.21 30.42 29.02 27.21 29.02 29.02 32.75
[97] 30.42 29.48 30.42 30.42

names(which(unlist(eapply(.GlobalEnv,is.data.frame))))

Output

[1] "x2" "x3"
raja
Published on 11-Feb-2021 11:38:51
Advertisements