0

I have a dataset that looks like this:

Responseid <- c("Responseid",1,2,3,4)
q1 <- c("what is your gender",1,1,1,1)
q2 <- c("what is your age",18,28,15,40)
df <- data.frame(Responseid,q1,q2)

enter image description here

I'm wondering how to put all the row 1 values as a label for the column header, so something like this: enter image description here

I have a dataset with a lot of variables and I want to put all the row 1 values as label for all the column header.

I would appreciate all the help there is! Thanks a lot!

Bruh
  • 277
  • 1
  • 6
  • 1
    you likely have a better solution upstream. When you import this data, you may consider setting an argument like `header = TRUE` to the function you call reading in the data, such as `read.csv(header = TRUE)` or with `readr::read_csv(col_names = TRUE)` – GuedesBF Apr 05 '23 at 18:21
  • I tried header=TRUE but it did not work – Bruh Apr 05 '23 at 18:23
  • Please see https://stackoverflow.com/questions/17797840/reading-two-line-headers-in-r – GuedesBF Apr 05 '23 at 18:24
  • Does this answer your question? [Reading two-line headers in R](https://stackoverflow.com/questions/17797840/reading-two-line-headers-in-r) – GuedesBF Apr 05 '23 at 18:24
  • https://stackoverflow.com/questions/2293131/reading-in-files-with-two-rows-for-header – GuedesBF Apr 05 '23 at 18:26
  • 1
    Also, if you're importing this data from Qualtrics or Survey Monkey or something like that there are dedicated packages that know how to read the data properly. – Gregor Thomas Apr 05 '23 at 18:28

0 Answers0