であっても、私はこの短いデータフレームを持って、すべての条件の値を含むように設定データをリシェイプ:すべての地域および年のエントリが値を含めるようにR - 彼らはゼロ
population.served <- c(200:210)
area <- c("Cambridge", "Oxford","Cambridge", "Oxford", "Cambridge", "Oxford","London","Cambridge", "Oxford", "London","Edinburgh")
year <- c("Year.1", "Year.1","Year.2", "Year.2","Year.3", "Year.3","Year.3", "Year.4", "Year.4","Year.4","Year.4")
data <- data.frame(population.served, area, year)
がどのように私はそれを作るのですかpopulation.servedはゼロ値であっても?
私は、データが次のようになりたい:
population.served <- c(200, 201, 0, 0, 202, 203, 0, 0, 204, 205, 206, 0, 207, 208, 209, 210)
area <- c("Cambridge", "Oxford","London","Edinburgh", "Cambridge", "Oxford","London","Edinburgh","Cambridge", "Oxford","London","Edinburgh","Cambridge", "Oxford","London","Edinburgh")
year <- c("Year.1", "Year.1","Year.1", "Year.1","Year.2", "Year.2","Year.2", "Year.2","Year.3", "Year.3","Year.3", "Year.3","Year.4", "Year.4","Year.4","Year.4")
data2 <- data.frame(population.served, area, year)