Skip to content

Instantly share code, notes, and snippets.

@danielecook
Created May 3, 2016 13:56
Show Gist options
  • Save danielecook/9bd19cbda9f566a224b7291f2b58bae9 to your computer and use it in GitHub Desktop.
Save danielecook/9bd19cbda9f566a224b7291f2b58bae9 to your computer and use it in GitHub Desktop.
Transpose data frame R
tFrame <- function(x) {
x <- t(x)
row_names <- row.names(x)[2:length(row.names(x))]
col_names <- x[1,]
x <- tbl_df(as.data.frame(x[2:nrow(x),]))
colnames(x) <- col_names
rownames(x) <- row_names
x <- dplyr::add_rownames(x, var = "strain")
x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment