Question

I have an object in R which saves a list of geneids and sequences.

$`140545`

[1] 

"GAAACATCCGAGGCTGGAGTGAGCCACGCGGAGGAGGAAGAACAGCCCGAGCTCACAGGGGCGGGGAAGAGTTCTAGCTCGCGACAGCCC"

$`57187`

[1] 

"CGGGCAGAGACGCTCCTCACTTTCCAGACTGGGCAGCCAGGCAGAGGGGCTCCTCACATCCCAGACGATGGGCGGCCAGGCAGAGAGGCTC"

I want to only store the ids in an object. e.g How will I achieve it in R

[1] 140545

[2] 57187

I am extremely new to R

Was it helpful?

Solution

ids <- names(your_list_object)

However, note that the ids will be saved as characters. So, if you want them numerically, you may have to use ids <- as.numeric(names(your_list_object)).

Also, R generally provides many easy ways to extract 'names' attributes from objects. For example look at ?names, ?rownames, ?colnames, ?dimnames etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top