[R] dplyr - add/expand rows

Hutchinson, David (EC) david.hutchinson at canada.ca
Sat Nov 25 20:18:31 CET 2017


I have a returned tibble of station operational record similar to the following:

> data.collection
# A tibble: 5 x 4
  STATION_NUMBER YEAR_FROM YEAR_TO RECORD
           <chr>     <int>   <int>  <chr>
1        07EA001      1960    1960    QMS
2        07EA001      1961    1970    QMC
3        07EA001      1971    1971    QMM
4        07EA001      1972    1976    QMC
5        07EA001      1977    1983    QRC

I would like to reshape this to one operational record (row) per year per station. Something like:

07EA001              1960      QMS
07EA001              1961      QMC
07EA001              1962      QMC
07EA001              1963      QMC
...
07EA001              1971      QMM

Can this be done in dplyr easily?

Thanks in advance,

David

	[[alternative HTML version deleted]]



More information about the R-help mailing list