Reputation: 29
First of all, I had to create a vector with three objects. So, I did:
three.objects <- c('pen', 'pencil', 'notebook')
Then, I had to create a vector with cost of three objects that correspond to three objects.
cost <- c('pen' <- 5, 'pencil' <- 10, 'notebook' <- 5)
Is the second one correct way to create a vector with values in it?
Upvotes: 0
Views: 50
Reputation: 887851
We can use setNames
to create a name
d` vector
cost <- setNames(c(5, 10, 5), three.objects)
cost
# pen pencil notebook
# 5 10 5
Upvotes: 1