0

This data is the total number of counts in "hour" for each "week".

> week    <- c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7)
> hour <- c("one","two","three","four","one","two","three","four","one","two","three","four","one","two","three","four","one","two","three","four","one","two","three","four","one","two","three","four")
> coun <- c(7,1,2,3,2,2,8,3,2,2,5,3,2,6,2,3,9,2,5,3,2,1,2,3,2,4,2,3)
> x <- data.frame(week,hour,coun)
> x
   week  hour coun
1     1   one    7
2     1   two    1
3     1 three    2
4     1  four    3
5     2   one    2
6     2   two    2
7     2 three    8
8     2  four    3
9     3   one    2
10    3   two    2
11    3 three    5
12    3  four    3
13    4   one    2
14    4   two    6
15    4 three    2
16    4  four    3
17    5   one    9
18    5   two    2
19    5 three    5
20    5  four    3
21    6   one    2
22    6   two    1
23    6 three    2
24    6  four    3
25    7   one    2
26    7   two    4
27    7 three    2
28    7  four    3

I want to convert this data to "week" on the vertical axis and "hour" on the horizontal axis. The image is like this

> one <- c(7,2,2,2,9,2,2)
> two <- c(1,2,2,6,2,1,4)
> three <- c(2,8,5,2,5,2,2)
> four <- c(3,3,3,3,3,3,3)
> y <- data.frame(one,two,three,four)
> y
  one two three four
1   7   1     2    3
2   2   2     8    3
3   2   2     5    3
4   2   6     2    3
5   9   2     5    3
6   2   1     2    3
7   2   4     2    3

Is there a function to accomplish this? I'm sorry for asking questions. Thank you.

Tim Ikata
  • 201
  • 1
  • 7

0 Answers0