0

After extracting tables from a PDF using tabulizer, my table looks like:

A King Blue
D Queen Red
T Prince Black

I want to move the variable names down as observations and replace them with a vector of strings with the actual column names:

letter rank colour
A King Blue
D Queen Red
T Prince Black
prayner
  • 393
  • 1
  • 10

1 Answers1

1
df <- rbind(names(df), df)
colnames(df) <- c("letter", "rank", "colour")

output

  letter   rank colour
1      A   King   Blue
2      D  Queen    Red
3      T Prince  Black

dplyr style:

df %>% 
  rbind(colnames(.), .) %>% 
  set_names(c("letter", "rank", "colour"))
Maël
  • 45,206
  • 3
  • 29
  • 67