Question: I have a data frame that i want to transpose (i suppose transpose is the correct word).
The code below will give a simplified Data frame.

```
tests <- c("TestA", "TestB", "TestC")
bg <- c(23, 13, 15)
s1 <- c(21,15,17)
s2 <- c(27,25,11)
s3 <- c(24,14,18)
df <- data.frame(tests,bg,s1,s2,s3)

```

I want to transpose/ reshape this to have the following structure:

[![enter image description here](https://i.stack.imgur.com/LG856.png)](https://i.stack.imgur.com/LG856.png)

Please keep in mind that there could be up to 20 tests, and 50 series (s1, s2....s50)

Answer: 
Get the data in long form and change the variable for wide form :

```
library(tidyr)
df %>%
  pivot_longer(cols = -tests) %>%
  pivot_wider(names_from = tests, values_from = value)

#  name  TestA TestB TestC
#  <chr> <dbl> <dbl> <dbl>
#1 bg       23    13    15
#2 s1       21    15    17
#3 s2       27    25    11
#4 s3       24    14    18

```

Or with `data.table` `dcast` + `melt`

```
library(data.table)
dcast(melt(setDT(df), id.vars = 'tests'), variable~tests, value.var = 'value')

```
Base R one-liner:

```
setNames(data.frame(t(df)[2:ncol(df),]), t(df$tests))

```