0

Is there a command/other way to get the value of a variable that is identical to a character string?

For instance, in the code below I would like to be able to get the value 2 from the call letters[2], because the second element of letters ("b") is the "same" as the variable name b.

b <- 2

letters[2]

[1] "b"

Is there a command that does this? Apologies if this has been asked before, I'm new to R.

Max
  • 1
  • 1
  • `get(letters[2])`. Why do you need this? This seems to by xy problem – pogibas Jun 09 '19 at 09:20
  • [xkcd](https://xkcd.com/974/) – pogibas Jun 09 '19 at 09:28
  • Thanks, that works. There most definitely will be a better solution to my problem, but I'm just trying to get something to work and I'm neither a programmer nor developer or any sort of PC wizard, so any ugly solution is fine by me as long as it does the job. – Max Jun 09 '19 at 09:36
  • Happy to help, best luck with your work – pogibas Jun 09 '19 at 09:40

0 Answers0