My data is grouped in month-year format under names of corresponding months. But I want to group them under their corresponding years.
I have a list like below: values are grouped under same months.
$Apr
$Apr$`04-2036`
date value
116 04-25-2036 1.14
117 04-26-2036 0.67
$Apr$`04-2037`
date value
478 04-22-2037 0
479 04-23-2037 0
$Mar
$Mar$`03-2037`
date value
446 03-21-2037 1.67
447 03-22-2037 0.00
$May
$May$`05-2036`
date value
146 05-25-2036 0.00
147 05-26-2036 2.31
And here is its structure:
sample<-structure(list(Apr = structure(list(`04-2036` = structure(list(
date = c("04-25-2036", "04-26-2036"), value = c(1.14, 0.67
)), .Names = c("date", "value"), row.names = 116:117, class = "data.frame"),
`04-2037` = structure(list(date = c("04-22-2037", "04-23-2037"
), value = c(0, 0)), .Names = c("date", "value"), row.names = 478:479, class = "data.frame")), .Names = c("04-2036",
"04-2037")), Mar = structure(list(`03-2037` = structure(list(
date = c("03-21-2037", "03-22-2037"), value = c(1.67, 0)), .Names = c("date",
"value"), row.names = 446:447, class = "data.frame")), .Names = "03-2037"),
May = structure(list(`05-2036` = structure(list(date = c("05-25-2036",
"05-26-2036"), value = c(0, 2.31)), .Names = c("date", "value"
), row.names = 146:147, class = "data.frame")), .Names = "05-2036")), .Names = c("Apr",
"Mar", "May"))
Desired output: data will be grouped under same years.
$`2036`
$`2036`$`04-2036`
date value
116 04-25-2036 1.14
117 04-26-2036 0.67
$`2036`$`05-2036`
date value
146 05-25-2036 0.00
147 05-26-2036 2.31
$`2037`
$`2037`$`03-2037`
date value
446 03-21-2037 1.67
447 03-22-2037 0.00
$`2037`$`04-2037`
date value
478 04-22-2037 0
479 04-23-2037 0
structure of output will be like this one:
output<-structure(list(`2036` = structure(list(`04-2036` = structure(list(
date = c("04-25-2036", "04-26-2036"), value = c(1.14, 0.67
)), .Names = c("date", "value"), row.names = 116:117, class = "data.frame"),
`05-2036` = structure(list(date = c("05-25-2036", "05-26-2036"
), value = c(0, 2.31)), .Names = c("date", "value"), row.names = 146:147, class = "data.frame")), .Names = c("04-2036",
"05-2036")), `2037` = structure(list(`03-2037` = structure(list(
date = c("03-21-2037", "03-22-2037"), value = c(1.67, 0)), .Names = c("date",
"value"), row.names = 446:447, class = "data.frame"), `04-2037` = structure(list(
date = c("04-22-2037", "04-23-2037"), value = c(0, 0)), .Names = c("date",
"value"), row.names = 478:479, class = "data.frame")), .Names = c("03-2037",
"04-2037"))), .Names = c("2036", "2037"))