简体   繁体   中英

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.

另外一个选项 :

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

这可以解决问题:

names_vec = character(length = 10)

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")
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM