-2

I have a problem accessing a part of the matrix rownames. My first line is:

rownames(K_taxon)[1]
                                                                                               ST-E00129:1035:HFHNFCCX2:1:1101:24931:49883;size=309 
"GGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTT"

I would like to get the line above the DNA code (ST-E00129....), because I need to run str_split on it. But the function runs only on the lower part inside the quotes.

Here is my dput output:

> dput(M_taxon[1:4, ])
structure(c("k__Fungi", "k__Fungi", "k__Fungi", "k__Fungi", "p__Basidiomycota", 
"p__Ascomycota", "p__Basidiomycota", "p__Basidiomycota", "c__Agaricomycetes", 
"c__Sordariomycetes", "c__Agaricomycetes", "c__Agaricomycetes", 
"o__Agaricales", "o__Magnaporthales", "o__Agaricales", "o__Agaricales", 
"f__Physalacriaceae", "f__Magnaporthaceae", "f__Inocybaceae", 
"f__Inocybaceae", "g__Mucidula", "g__Ophioceras", "g__Inocybe", 
"g__Inocybe", "s__brunneomarginata", "s__dolichostomum", "s__leptophylla", 
"s__rimulosa"), .Dim = c(4L, 7L), .Dimnames = list(c("GGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTTAGGGTTT", 
"CCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAA", 
"TCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTAT", 
"TAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGAT"
), c("Kingdom", "Phylum", "Class", "Order", "Family", "Genus", 
"Species")))

Matevz

tuintam10
  • 3
  • 2
  • Please read this guide on how to ask a good question and make a minimal working example. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610 – MrGumble Feb 11 '21 at 08:57
  • Thank you for pointing me to the page with instructions, but if I would know how to generate a minimal working example by hand, I wouldn't have a problem, because I would know how to access things. – tuintam10 Feb 11 '21 at 09:05
  • Can you add `dput(K_taxon[1:4, ])` to your post? – Ronak Shah Feb 11 '21 at 09:32
  • I have added the dput output. I left it out of the original post, as it doesn't print the part of the rownames that I am interested in. – tuintam10 Feb 12 '21 at 07:23

1 Answers1

0

It seems your matrix K_taxon has an oddity on its rownames, because as far as I can see, the rownames themselves is a named vector...

Use names(rownames(K_taxon)[1]) (incidentally you can also use names(rownames(K_taxon))[1]).

MrGumble
  • 5,631
  • 1
  • 18
  • 33