用于创建索引文件的代码。
#create index
pacman::p_load(data.table)
#library(data.table)
webdata <- fread("http://datafeed.deohs.washington.edu/ACT/
calibrated_dataset_for_shiny.csv")
indexvalue <-
data.table(index=webdata[,.I[!duplicated(webdata[,c("month","year")])]],
unique(webdata[,c("month","year")]))
indexvalue <- rbindlist(list(indexvalue, data.table(index=nrow(webdata),
month=6,year=2017)))
write.csv(indexvalue,"index_reference.csv")
作为index_reference生成的输出。
"","index","month","year"
"1",1,9,2018
"2",470,8,2018
"3",24438,6,2017
应生成的输出。问题在于索引列表没有在每年的每个月中创建一行。如何创建索引以在数据中显示每月/每年?
"","index","month","year"
"1",1,9,2018
"2",470,8,2018
"3",#####,7,2018
"4",#####,6,2018
"5",#####,5,2018
"6",#####,4,2018
"7",#####,3,2018
"8",#####,2,2018
"9",#####,1,2018
"10",#####,12,2017
"11",#####,11,2017
"12",#####,10,2017
"13",#####,9,2017
"14",#####,8,2017
"15",#####,7,2017
"16",24438,6,2017