0

I am a total R novice and I couldn't even figure out how to make an example of my data table. How do I make a pastable example of this 10x7 table shown below as a text example which you noramlly see on stack overflow? My real question is how to make this into Long format though.

enter image description here

Emil Krabbe
  • 101
  • 9
  • 1. You haven't read the data correctly. All the headers are 1st row. Use `header = TRUE` in `read.csv` or whatever you are using to read the data. 2. To get the data in long format try the solutions from this post https://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format – Ronak Shah Mar 12 '21 at 09:59
  • Yes I realize but I was not sure if "time" (all the weeks from 2021-2000) had to be in the header or not? What do you think is easier – Emil Krabbe Mar 12 '21 at 10:01
  • Fine to load in with time as header, you can pivot it longer from that. – Jon Spring Mar 12 '21 at 10:16
  • I will load time as header but then I still have age, sex, unit, and country (Identifier) as headers also. Is there a way to tell R that time start from header 5? – Emil Krabbe Mar 12 '21 at 10:29
  • The "tidyverse" way would be to say `my_data %>% pivot_longer(-c(age:'geo\time'))` – Jon Spring Mar 12 '21 at 18:52
  • The easiest way to paste a 10x7 table would be to say `dput(my_data[1:10,1:7])` and paste that code into your question. Another great option is the `datapasta` package which lets you paste your clipboard as a data frame. – Jon Spring Mar 12 '21 at 18:54

0 Answers0