0

This is my first question on here so forgive me if I am not doing this right. I am still learning R.

I have data frame that looks something like this

DF
Status score
Test    2
Test    4
Control 5
Control 6

What I want to do is essentially transpose the data so I have a column labeled test and a column labeled Control with the values listed below. preferably with dyplr

1 Answers1

0

With tidyverse, we create a sequence column by 'Status', then reshape back to 'wide' format with pivot_wider

library(dplyr)
library(tidyr)
DF %>% 
    group_by(Status) %>%
    mutate(rn = row_number()) %>%
    ungroup %>%
    pivot_wider(names_from = Status, values_from = score) %>%
    select(-rn)
akrun
  • 874,273
  • 37
  • 540
  • 662