Reputation: 2054
I use a gene expression package that outputs a named matrix. In order to get this into a tibble, I always have to first cast it to a data.frame
so that I can then convert the rownames. Is there a shorter way of doing this? eg:
library(tidyverse)
normalized_counts %>%
as.data.frame() %>%
rownames_to_column('name') %>%
gather(key = experiment, value = expression, -name) %>%
as_tibble()
Where I would much prefer to do something like:
library(tidyverse)
normalized_counts %>%
as_tibble() %>%
rownames_to_column('name') %>%
gather(key = experiment, value = expression, -name)
But I can't because I loose the rownames at the as_tibble
step.
Upvotes: 0
Views: 54
Reputation: 2054
as_tibble
has a rownames arugument you can use.
library(tidyverse)
normalized_counts %>%
as_tibble(rownames = 'name') %>%
gather(key = experiment, value = expression, -name)
Upvotes: 1