I have a string and and a number
cID = 'x1'
num = 1
I want to create a named vector
nvec = c(x1 = num)
but when I do the following, R interprets cID as 'cID' and not as 'x1'.
nvec = c(cID = num)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For a one-line solution, use
setNames():For an example in which
setName()supplied a clean and elegant solution to a tricky problem, see @hadley’s answer to this question.