Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Say I have type1 <- "M"
type1 <- "M"
and myvec <- c(2,4,6,8)
myvec <- c(2,4,6,8)
How can I assign myvec to type1 so when I just type M, I could get myvec elements?
myvec
type1
M
Is there something like assign(type1) <- myvec?
assign(type1) <- myvec
assign(type1, myvec)
Will assign the variable indicated by type1 ("M") to the value contained in myvec.
"M"
Add a comment
If we need to use <-, an option is to select the environment (in this case the .GlobalEnv and use [[ for assignment
<-
.GlobalEnv
[[
.GlobalEnv[[type1]] <- myvec M #[1] 2 4 6 8
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.