____
__________________________
_________________
_________________
_____________
1989
9.7986
6.9929
7.5714
6.9146
1985
NaN
8.4406
8.4264
7.75
This representation of the annual means by site has an advantage and a disadvantage.
• It is easier to look at the short five-year time series for each site. After unstacking, each site has
its own variable in pivotedMeanNO2bySiteID. You can easily compare sites to each other.
• It is harder to sort and pick out the largest values across the whole pivoted table. After
unstacking, pivotedMeanNO2bySiteID has 443 variables. The stacked version,
meanNO2bySite, has only seven variables.
Group by Time and Another Grouping Variable
To group data in NO2data by year and another grouping variable, it was necessary to add Year as an
additional variable. Also, the output from groupsummary is a table even when the input is a
timetable. But suppose you want to keep the results in a timetable instead. The retime function can
also produce annual summaries. But it can group data only by time. To group data by site and by year,
rearrange NO2data so that you can call retime on a timetable where the NO2 concentrations are
already grouped by site.
Group the raw data in NO2data by site by using the unstack function. The output timetable has a
separate variable for each site. This timetable looks similar to a pivot table. But instead of having
means or some other statistic, NO2bySite has all the raw data. It is just reorganized. For further
convenience, sort the rows of the timetable by their row times so that the earliest timestamps come
first.
NO2bySite = unstack(NO2data,"MeasuredNO2","SiteID","GroupingVariable","Timestamp");
NO2bySite = sortrows(NO2bySite)
NO2bySite=43824×442 timetable
Timestamp
Alaska_KenaiPeninsula_1004
Arizona_Apache_10
Arizona_Apache_11
____________________
__________________________
_________________
_________________
01-Jan-1985 00:00:00
NaN
NaN
NaN
01-Jan-1985 01:00:00
NaN
NaN
NaN
⋮
In this format you can easily plot the raw data by using the stackedplot function. This plot shows
NO2 concentrations for each site as a function of time.
stackedplot(NO2bySite)
Grouped Calculations in Tables and Timetables
9-95
Précédent

- 439/1450

Suivant