Groupby and transform two columns in df into matrix R [duplicate]
问题 This question already has answers here : Create columns from factors and count [duplicate] (2 answers) Closed 3 years ago . I would like to convert the following data.frame into a matrix where the the number of each bike station id that occurs per hour is counted. > dim(test) [1] 80623 5 head(test, n = 10) bikeid end.station.id start.station.id diff.time hour 1 16052 244 322 6544 14 2 16052 284 432 3406 21 3 16052 461 519 33416 3 4 16052 228 519 26876 13 5 16052 72 435 388 17 6 16052 319 127