1

Say I have type1 <- "M"

and myvec <- c(2,4,6,8)

How can I assign myvec to type1 so when I just type M, I could get myvec elements?

Is there something like assign(type1) <- myvec?

2 Answers 2

1
assign(type1, myvec)

Will assign the variable indicated by type1 ("M") to the value contained in myvec.

Sign up to request clarification or add additional context in comments.

Comments

1

If we need to use <-, an option is to select the environment (in this case the .GlobalEnv and use [[ for assignment

.GlobalEnv[[type1]] <- myvec
M
#[1] 2 4 6 8

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.