1

I have a vector (test_vector), and it contains a string; that string is also the name of a dataframe. I need a function that will allow me to display the dataframe knowing given a value in test-vector:

test_vector = "x"
x = tibble(y=seq(1,5))
testdata[1]

What I want is an function that wraps around testdata[1] and returns the dataframe x, not the "x" value of test_vector[1]

Does such a function exist in R.

evidently
  • 43
  • 4

1 Answers1

4

We can use get to return the value of the object

get(test_vector[1])

-output

# A tibble: 5 x 1
#      y
#  <int>
#1     1
#2     2
#3     3
#4     4
#5     5

Or another option is to directly checking the .GlobalEnv

.GlobalEnv[[test_vector[1]]]
akrun
  • 874,273
  • 37
  • 540
  • 662