Skip to content

Instantly share code, notes, and snippets.

@javieroot
Forked from danielecook/transpose_dataframe.R
Created December 2, 2017 20:25
Show Gist options
  • Save javieroot/c53e5dd0bb6ebe13f08d2f3dde452870 to your computer and use it in GitHub Desktop.
Save javieroot/c53e5dd0bb6ebe13f08d2f3dde452870 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