Skip to content

Instantly share code, notes, and snippets.

@klmr
Last active August 29, 2015 14:15
Show Gist options
  • Save klmr/c691412a4f65a2697180 to your computer and use it in GitHub Desktop.
Save klmr/c691412a4f65a2697180 to your computer and use it in GitHub Desktop.
library(dplyr)
counts = data.frame(Gene = c('A', 'B', 'C', 'D'),
Length = 1:4,
do1 = c(10, 20, 30, 40),
do2 = c(20, 40, 60, 80),
do3 = c(20, 20, 30, 40))
tpm = counts %>%
mutate_each(funs(. / Length), starts_with('do')) %>%
mutate_each(funs(1e6 * . / sum(.)), starts_with('do'))
tpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment