Reputation:
I want to store names in other vector. So, first I will have to create an empty vector to store these names. I know how to define numeric vector. g <- numeric(length=10). But not sure about how to define vector to store names.
Upvotes: 2
Views: 5045
Reputation: 4161
If you do not know the number of values in advance, you can start with an empty vector and append to it. This is slow, so don't do it for large quantities of data.
names <- c()
for (r in 1:numNames) {
names <- append(names, "someName")
}
Upvotes: 0
Reputation: 121568
Another option :
names_vec <- vector(mode='character',length=10)
Upvotes: 5