Using t, gives a matrix, thus as.data.frame.
library(dplyr) dat[-1] %>% t() %>% as.data.frame() %>% setNames(dat[,1]) # A B C D E # Claims 0 0 2 6 7 # Adds 10 17 16 15 12 # Family 1 1 2 1 3 # Individual 9 9 5 6 9 # ES 6 2 6 6 8 # SO 4 6 4 4 6
or without dplyr:
setNames(as.data.frame(t(dat[-1])), dat[,1]) # A B C D E # Claims 0 0 2 6 7 # Adds 10 17 16 15 12 # Family 1 1 2 1 3 # Individual 9 9 5 6 9 # ES 6 2 6 6 8 # SO 4 6 4 4 6
Edit
To get the rownames as column there's tibble::rownames_to_column
dat[-1] %>% t() %>% as.data.frame() %>% setNames(dat[,1]) %>% tibble::rownames_to_column("xyz") # xyz A B C D E # 1 Claims 0 0 2 6 7 # 2 Adds 10 17 16 15 12 # 3 Family 1 1 2 1 3 # 4 Individual 9 9 5 6 9 # 5 ES 6 2 6 6 8 # 6 SO 4 6 4 4 6
or without packages:
setNames(data.frame(names(dat)[-1], unname(t(dat[-1]))), c("xyz", dat[,1])) # xyz A B C D E # 1 Claims 0 0 2 6 7 # 2 Adds 10 17 16 15 12 # 3 Family 1 1 2 1 3 # 4 Individual 9 9 5 6 9 # 5 ES 6 2 6 6 8 # 6 SO 4 6 4 4 6
Data:
dat <- structure(list(Type = c("A", "B", "C", "D", "E"), Claims = c(0L, 0L, 2L, 6L, 7L), Adds = c(10L, 17L, 16L, 15L, 12L), Family = c(1L, 1L, 2L, 1L, 3L), Individual = c(9L, 9L, 5L, 6L, 9L), ES = c(6L, 2L, 6L, 6L, 8L), SO = c(4L, 6L, 4L, 4L, 6L)), class = "data.frame", row.names = c(NA, -5L))