Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract variable names from list or vector in R

Assuming:

aa = c('A','B','C')
bb = c('D','E','F')
list1 = list(aa,bb)
vect1 = c(aa,bb)

Is there a way to extract the variable names as strings ('aa', 'bb') from either list1 or vect1? Is this information being stored in lists and vectors? If not, what would be the appropriate format?

Thanks in advance!

like image 872
Daan11 Avatar asked Oct 16 '25 05:10

Daan11


1 Answers

For the situation what you have done the answer is no. But if you are ready to do some changes in your code then you can easily get it,

list1 <- list( aa = aa, bb = bb)

Now you can easily access the string version of names of variables from which list is formed,

names(list1)
like image 111
jack jay Avatar answered Oct 18 '25 18:10

jack jay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!