0

So I am trying to convert the data from wide to long format so I can plot a line graph, however, I'm completely stuck on how to do this. My vision for the line graph is to have the score as the 'y' and the days along the 'x' axis with each participant representing a different line.

 Participant Day.1 Day.2 Day.3 Day.4 Day.5 Day.6 Day.7 Day.8 Day.9 Day.10 Day.11 Day.12 Day.13 Day.14 Day.15 Day.16
1         P03  2330  2290  2340  3820  3740  2260  2340  2300  2270   2300   2340   2340   2220   2260   2340   2340
2         P04  2330  2300  2340  2340  2340  2340    NA    NA    NA     NA     NA     NA     NA     NA     NA     NA
3         P05  4580  2200  2210  2210  2230  2260  2210  2340  2260   2340   2150   2010   2260   2280   2230   2330
4         P07  2340  2300  2340  2220  2300  2340  2250  2340  2340   2340   2340   2340   2340   2340   2340   2340
  Day.17 Day.18 Day.19 Day.20 Day.21 Day.22 Day.23 Day.24 Day.25 Day.26 Day.27 Day.28
1     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA
2     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA
3    320   2180   2340   2340   2220     NA     NA     NA     NA     NA     NA     NA
4   2340   2340   2300   2340   2340   2340   2300   2300   2340   2340   2300   2340

There are also some missing values so I know I may run into some problems with this as well. Please can anyone help me with this? Thank you in advance :)

JacobHad
  • 33
  • 4
  • 1
    `tidyr::pivot_longer(data, Day.1:Day.28, names_to = "Day", values_to = "Score")` – zephryl Oct 28 '22 at 04:26
  • Thank you SO much! you won't believe how long i spent just on this little thing, you've just saved me a lot of time! You're a lifesaver :) – JacobHad Oct 28 '22 at 04:36

0 Answers0