merge with remote
[aggexp.git] / pkg / R / z_getData.R
... / ...
CommitLineData
1#' @title Get forecasts + observations
2#'
3#' @description Get forecasts of all specified experts for all specified stations, also with (ordered) dates and (unordered) stations indices.
4#'
5#' @param station List of stations dataframes (as in the sample)
6#' @param experts Names of the experts (as in dataframe header)
7#'
8#' @export
9getData = function(stations, experts)
10{
11 data = as.data.frame(matrix(nrow=0, ncol=1 + length(experts) + 2))
12 names(data) = c("Date", experts, "Measure", "Station")
13 for (i in 1:length(stations))
14 {
15 #date index is sufficient; also add station index
16 stationInfo = cbind(
17 Date = 1:nrow(stations[[i]]),
18 stations[[i]] [,names(stations[[i]]) %in% experts],
19 Measure = stations[[i]][,"Measure"],
20 Station = i)
21 data = rbind(data, stationInfo)
22 }
23
24 #extra step: order by date (would be a DB request)
25 data = data[order(data[,"Date"]),]
26
27 return (data)
28}