0

If I have a variable

x <- "foo"

and another variable

y <- 1:5

is there a way I can rename y to foo while keeping it equal to 1:5?

D Gordon
  • 47
  • 4
  • 4
    May be `assign` `assign(x, y); foo# [1] 123` – akrun Jun 12 '15 at 13:40
  • sorry, what you suggested worked for what I asked specifically, but in my much more complicated code it keeps giving me an error. I assumed because what I was trying to preserve is a long vector, not a number, thats why I edited it. However, what you suggested does work for my edits, not sure what the issue is and my code is way to long to post so thats why I simplified it. I keep getting the error that I have an invalid first argument within assign. – D Gordon Jun 12 '15 at 13:58
  • Never mind, got it working, thanks for the help! – D Gordon Jun 12 '15 at 14:02
  • @akrun That should be an answer, no? To me, it's clear what's being asked here, though it may be a dupe. (And the answer I currently see below makes no sense to me.) – Frank Jun 12 '15 at 16:01
  • 1
    @Frank It looks like a dupe. but I can't vote to close as I already voted for it. – akrun Jun 12 '15 at 16:05

1 Answers1

0

You could use comment() so that foo was an attribute of y. For example, try:

x <- "foo"
y <- 1:5

comment(y) <- x

str(y)
attr(y, "comment")
Daniel Anderson
  • 2,394
  • 13
  • 26