user2409011
user2409011

Reputation:

How to define an empty vector to store 'names' in R?

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

Answers (3)

radumanolescu
radumanolescu

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

agstudy
agstudy

Reputation: 121568

Another option :

  names_vec  <- vector(mode='character',length=10)

Upvotes: 5

Paul Hiemstra
Paul Hiemstra

Reputation: 60924

This does the trick:

names_vec = character(length = 10)

Upvotes: 2

Related Questions