У меня есть объект списка со многими отдельными списками значений длиной не более 12. Не все имеют длину 12 (как видно из приведенных ниже данных).Извлечь значения списка в стандартизованный фрейм данных
Я хотел бы извлечь значения в фрейм данных x * 12, где x - количество списков (так 50 в этом случае). Если список не имеет всех 12 значений, я надеюсь ввести пробел. Поэтому, если есть только одно значение (например, в строке 35), это будет в 35-й строке и 1-м столбце, а 2-12-й столбцы для этой строки будут иметь введенные пробелы.
До сих пор мои усилия были сосредоточены на таких вещах, как test105 ниже, для учета различного количества строк и столбцов. Есть ли способ стандартизации заранее, чтобы обеспечить формат данных?
test105=sapply(test99,"[[",1)
Я также преобразовал список структуры «test99» с помощью команды as.matrix, но это, кажется, не дает мне больше гибкости, чем другие, видя данные более четко.
Благодарим за помощь.
dput(test99transfer)
structure(list(`1` = structure(c("3.631412983", "1.351914048",
"-1.82656002", "-3.531716108", "0.468971014", "-0.510936022",
"2.025001049", "4.369469166", "0.574441016", "-0.397388995",
"3.314476013", "2.016448021"), .Names = c("Feb 2012", "Mar 2012",
"Apr 2012", "May 2012", "Jun 2012", "Jul 2012", "Aug 2012", "Sep 2012",
"Oct 2012", "Nov 2012", "Dec 2012", "Jan 2013")), `2` = structure(c("1.351914048",
"-1.82656002", "-3.531716108", "0.468971014", "-0.510936022",
"2.025001049", "4.369469166", "0.574441016", "-0.397388995",
"3.314476013", "2.016448021", "0.041545"), .Names = c("Mar 2012",
"Apr 2012", "May 2012", "Jun 2012", "Jul 2012", "Aug 2012", "Sep 2012",
"Oct 2012", "Nov 2012", "Dec 2012", "Jan 2013", "Feb 2013")),
`3` = structure(c("-1.82656002", "-3.531716108", "0.468971014",
"-0.510936022", "2.025001049", "4.369469166", "0.574441016",
"-0.397388995", "3.314476013", "2.016448021", "0.041545",
"1.944175005"), .Names = c("Apr 2012", "May 2012", "Jun 2012",
"Jul 2012", "Aug 2012", "Sep 2012", "Oct 2012", "Nov 2012",
"Dec 2012", "Jan 2013", "Feb 2013", "Mar 2013")), `4` = structure(c("-3.531716108",
"0.468971014", "-0.510936022", "2.025001049", "4.369469166",
"0.574441016", "-0.397388995", "3.314476013", "2.016448021",
"0.041545", "1.944175005", "0.898332"), .Names = c("May 2012",
"Jun 2012", "Jul 2012", "Aug 2012", "Sep 2012", "Oct 2012",
"Nov 2012", "Dec 2012", "Jan 2013", "Feb 2013", "Mar 2013",
"Apr 2013")), `5` = structure(c("0.468971014", "-0.510936022",
"2.025001049", "4.369469166", "0.574441016", "-0.397388995",
"3.314476013", "2.016448021", "0.041545", "1.944175005",
"0.898332", "1.043239951"), .Names = c("Jun 2012", "Jul 2012",
"Aug 2012", "Sep 2012", "Oct 2012", "Nov 2012", "Dec 2012",
"Jan 2013", "Feb 2013", "Mar 2013", "Apr 2013", "May 2013"
)), `6` = structure(c("-0.510936022", "2.025001049", "4.369469166",
"0.574441016", "-0.397388995", "3.314476013", "2.016448021",
"0.041545", "1.944175005", "0.898332", "1.043239951", "0.722914994"
), .Names = c("Jul 2012", "Aug 2012", "Sep 2012", "Oct 2012",
"Nov 2012", "Dec 2012", "Jan 2013", "Feb 2013", "Mar 2013",
"Apr 2013", "May 2013", "Jun 2013")), `7` = structure(c("2.025001049",
"4.369469166", "0.574441016", "-0.397388995", "3.314476013",
"2.016448021", "0.041545", "1.944175005", "0.898332", "1.043239951",
"0.722914994", "-0.349180996"), .Names = c("Aug 2012", "Sep 2012",
"Oct 2012", "Nov 2012", "Dec 2012", "Jan 2013", "Feb 2013",
"Mar 2013", "Apr 2013", "May 2013", "Jun 2013", "Jul 2013"
)), `8` = structure(c("4.369469166", "0.574441016", "-0.397388995",
"3.314476013", "2.016448021", "0.041545", "1.944175005",
"0.898332", "1.043239951", "0.722914994", "-0.349180996",
"0.074822001"), .Names = c("Sep 2012", "Oct 2012", "Nov 2012",
"Dec 2012", "Jan 2013", "Feb 2013", "Mar 2013", "Apr 2013",
"May 2013", "Jun 2013", "Jul 2013", "Aug 2013")), `9` = structure(c("0.574441016",
"-0.397388995", "3.314476013", "2.016448021", "0.041545",
"1.944175005", "0.898332", "1.043239951", "0.722914994",
"-0.349180996", "0.074822001", "-1.258324027"), .Names = c("Oct 2012",
"Nov 2012", "Dec 2012", "Jan 2013", "Feb 2013", "Mar 2013",
"Apr 2013", "May 2013", "Jun 2013", "Jul 2013", "Aug 2013",
"Sep 2013")), `10` = structure(c("-0.397388995", "3.314476013",
"2.016448021", "0.041545", "1.944175005", "0.898332", "1.043239951",
"0.722914994", "-0.349180996", "0.074822001", "-1.258324027",
"1.153113008"), .Names = c("Nov 2012", "Dec 2012", "Jan 2013",
"Feb 2013", "Mar 2013", "Apr 2013", "May 2013", "Jun 2013",
"Jul 2013", "Aug 2013", "Sep 2013", "Oct 2013")), `11` = structure(c("3.314476013",
"2.016448021", "0.041545", "1.944175005", "0.898332", "1.043239951",
"0.722914994", "-0.349180996", "0.074822001", "-1.258324027",
"1.153113008", "1.344225049"), .Names = c("Dec 2012", "Jan 2013",
"Feb 2013", "Mar 2013", "Apr 2013", "May 2013", "Jun 2013",
"Jul 2013", "Aug 2013", "Sep 2013", "Oct 2013", "Nov 2013"
)), `12` = structure(c("2.016448021", "0.041545", "1.944175005",
"0.898332", "1.043239951", "0.722914994", "-0.349180996",
"0.074822001", "-1.258324027", "1.153113008", "1.344225049",
"2.703722954"), .Names = c("Jan 2013", "Feb 2013", "Mar 2013",
"Apr 2013", "May 2013", "Jun 2013", "Jul 2013", "Aug 2013",
"Sep 2013", "Oct 2013", "Nov 2013", "Dec 2013")), `13` = structure(c("0.041545",
"1.944175005", "0.898332", "1.043239951", "0.722914994",
"-0.349180996", "0.074822001", "-1.258324027", "1.153113008",
"1.344225049", "2.703722954", "-1.334722042"), .Names = c("Feb 2013",
"Mar 2013", "Apr 2013", "May 2013", "Jun 2013", "Jul 2013",
"Aug 2013", "Sep 2013", "Oct 2013", "Nov 2013", "Dec 2013",
"Jan 2014")), `14` = structure(c("1.944175005", "0.898332",
"1.043239951", "0.722914994", "-0.349180996", "0.074822001",
"-1.258324027", "1.153113008", "1.344225049", "2.703722954",
"-1.334722042", "1.17830801"), .Names = c("Mar 2013", "Apr 2013",
"May 2013", "Jun 2013", "Jul 2013", "Aug 2013", "Sep 2013",
"Oct 2013", "Nov 2013", "Dec 2013", "Jan 2014", "Feb 2014"
)), `15` = structure(c("0.898332", "1.043239951", "0.722914994",
"-0.349180996", "0.074822001", "-1.258324027", "1.153113008",
"1.344225049", "2.703722954", "-1.334722042", "1.17830801",
"1.743324995"), .Names = c("Apr 2013", "May 2013", "Jun 2013",
"Jul 2013", "Aug 2013", "Sep 2013", "Oct 2013", "Nov 2013",
"Dec 2013", "Jan 2014", "Feb 2014", "Mar 2014")), `16` = structure(c("1.043239951",
"0.722914994", "-0.349180996", "0.074822001", "-1.258324027",
"1.153113008", "1.344225049", "2.703722954", "-1.334722042",
"1.17830801", "1.743324995", "0.075165004"), .Names = c("May 2013",
"Jun 2013", "Jul 2013", "Aug 2013", "Sep 2013", "Oct 2013",
"Nov 2013", "Dec 2013", "Jan 2014", "Feb 2014", "Mar 2014",
"Apr 2014")), `17` = structure(c("0.722914994", "-0.349180996",
"0.074822001", "-1.258324027", "1.153113008", "1.344225049",
"2.703722954", "-1.334722042", "1.17830801", "1.743324995",
"0.075165004", "0.368221998"), .Names = c("Jun 2013", "Jul 2013",
"Aug 2013", "Sep 2013", "Oct 2013", "Nov 2013", "Dec 2013",
"Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014", "May 2014"
)), `18` = structure(c("-0.349180996", "0.074822001", "-1.258324027",
"1.153113008", "1.344225049", "2.703722954", "-1.334722042",
"1.17830801", "1.743324995", "0.075165004", "0.368221998",
"1.140485048"), .Names = c("Jul 2013", "Aug 2013", "Sep 2013",
"Oct 2013", "Nov 2013", "Dec 2013", "Jan 2014", "Feb 2014",
"Mar 2014", "Apr 2014", "May 2014", "Jun 2014")), `19` = structure(c("0.074822001",
"-1.258324027", "1.153113008", "1.344225049", "2.703722954",
"-1.334722042", "1.17830801", "1.743324995", "0.075165004",
"0.368221998", "1.140485048", "-0.521915972"), .Names = c("Aug 2013",
"Sep 2013", "Oct 2013", "Nov 2013", "Dec 2013", "Jan 2014",
"Feb 2014", "Mar 2014", "Apr 2014", "May 2014", "Jun 2014",
"Jul 2014")), `20` = structure(c("-1.258324027", "1.153113008",
"1.344225049", "2.703722954", "-1.334722042", "1.17830801",
"1.743324995", "0.075165004", "0.368221998", "1.140485048",
"-0.521915972", "0.721825004"), .Names = c("Sep 2013", "Oct 2013",
"Nov 2013", "Dec 2013", "Jan 2014", "Feb 2014", "Mar 2014",
"Apr 2014", "May 2014", "Jun 2014", "Jul 2014", "Aug 2014"
)), `21` = structure(c("1.153113008", "1.344225049", "2.703722954",
"-1.334722042", "1.17830801", "1.743324995", "0.075165004",
"0.368221998", "1.140485048", "-0.521915972", "0.721825004",
"-0.468360007"), .Names = c("Oct 2013", "Nov 2013", "Dec 2013",
"Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014", "May 2014",
"Jun 2014", "Jul 2014", "Aug 2014", "Sep 2014")), `22` = structure(c("1.344225049",
"2.703722954", "-1.334722042", "1.17830801", "1.743324995",
"0.075165004", "0.368221998", "1.140485048", "-0.521915972",
"0.721825004", "-0.468360007", "0.696716011"), .Names = c("Nov 2013",
"Dec 2013", "Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014",
"May 2014", "Jun 2014", "Jul 2014", "Aug 2014", "Sep 2014",
"Oct 2014")), `23` = structure(c("2.703722954", "-1.334722042",
"1.17830801", "1.743324995", "0.075165004", "0.368221998",
"1.140485048", "-0.521915972", "0.721825004", "-0.468360007",
"0.696716011", "-0.181444004"), .Names = c("Dec 2013", "Jan 2014",
"Feb 2014", "Mar 2014", "Apr 2014", "May 2014", "Jun 2014",
"Jul 2014", "Aug 2014", "Sep 2014", "Oct 2014", "Nov 2014"
)), `24` = structure(c("-1.334722042", "1.17830801", "1.743324995",
"0.075165004", "0.368221998", "1.140485048", "-0.521915972",
"0.721825004", "-0.468360007", "0.696716011", "-0.181444004",
"0.585435987"), .Names = c("Jan 2014", "Feb 2014", "Mar 2014",
"Apr 2014", "May 2014", "Jun 2014", "Jul 2014", "Aug 2014",
"Sep 2014", "Oct 2014", "Nov 2014", "Dec 2014")), `25` = structure(c("1.17830801",
"1.743324995", "0.075165004", "0.368221998", "1.140485048",
"-0.521915972", "0.721825004", "-0.468360007", "0.696716011",
"-0.181444004", "0.585435987"), .Names = c("Feb 2014", "Mar 2014",
"Apr 2014", "May 2014", "Jun 2014", "Jul 2014", "Aug 2014",
"Sep 2014", "Oct 2014", "Nov 2014", "Dec 2014")), `26` = structure(c("1.743324995",
"0.075165004", "0.368221998", "1.140485048", "-0.521915972",
"0.721825004", "-0.468360007", "0.696716011", "-0.181444004",
"0.585435987"), .Names = c("Mar 2014", "Apr 2014", "May 2014",
"Jun 2014", "Jul 2014", "Aug 2014", "Sep 2014", "Oct 2014",
"Nov 2014", "Dec 2014")), `27` = structure(c("0.075165004",
"0.368221998", "1.140485048", "-0.521915972", "0.721825004",
"-0.468360007", "0.696716011", "-0.181444004", "0.585435987"
), .Names = c("Apr 2014", "May 2014", "Jun 2014", "Jul 2014",
"Aug 2014", "Sep 2014", "Oct 2014", "Nov 2014", "Dec 2014"
)), `28` = structure(c("0.368221998", "1.140485048", "-0.521915972",
"0.721825004", "-0.468360007", "0.696716011", "-0.181444004",
"0.585435987"), .Names = c("May 2014", "Jun 2014", "Jul 2014",
"Aug 2014", "Sep 2014", "Oct 2014", "Nov 2014", "Dec 2014"
)), `29` = structure(c("1.140485048", "-0.521915972", "0.721825004",
"-0.468360007", "0.696716011", "-0.181444004", "0.585435987"
), .Names = c("Jun 2014", "Jul 2014", "Aug 2014", "Sep 2014",
"Oct 2014", "Nov 2014", "Dec 2014")), `30` = structure(c("-0.521915972",
"0.721825004", "-0.468360007", "0.696716011", "-0.181444004",
"0.585435987"), .Names = c("Jul 2014", "Aug 2014", "Sep 2014",
"Oct 2014", "Nov 2014", "Dec 2014")), `31` = structure(c("0.721825004",
"-0.468360007", "0.696716011", "-0.181444004", "0.585435987"
), .Names = c("Aug 2014", "Sep 2014", "Oct 2014", "Nov 2014",
"Dec 2014")), `32` = structure(c("-0.468360007", "0.696716011",
"-0.181444004", "0.585435987"), .Names = c("Sep 2014", "Oct 2014",
"Nov 2014", "Dec 2014")), `33` = structure(c("0.696716011",
"-0.181444004", "0.585435987"), .Names = c("Oct 2014", "Nov 2014",
"Dec 2014")), `34` = structure(c("-0.181444004", "0.585435987"
), .Names = c("Nov 2014", "Dec 2014")), `35` = structure("0.585435987", .Names = "Dec 2014"),
`36` = structure(c("1.043239951", "0.722914994", "-0.349180996",
"0.074822001", "-1.258324027", "1.153113008", "1.344225049",
"2.703722954", "-1.334722042", "1.17830801", "1.126680017",
""), .Names = c("May 2013", "Jun 2013", "Jul 2013", "Aug 2013",
"Sep 2013", "Oct 2013", "Nov 2013", "Dec 2013", "Jan 2014",
"Feb 2014", "Mar 2014", "Apr 2014")), `37` = structure(c("0.722914994",
"-0.349180996", "0.074822001", "-1.258324027", "1.153113008",
"1.344225049", "2.703722954", "-1.334722042", "1.17830801",
"1.126680017", "", ""), .Names = c("Jun 2013", "Jul 2013",
"Aug 2013", "Sep 2013", "Oct 2013", "Nov 2013", "Dec 2013",
"Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014", "May 2014"
)), `38` = structure(c("-0.349180996", "0.074822001", "-1.258324027",
"1.153113008", "1.344225049", "2.703722954", "-1.334722042",
"1.17830801", "1.126680017", "", "", ""), .Names = c("Jul 2013",
"Aug 2013", "Sep 2013", "Oct 2013", "Nov 2013", "Dec 2013",
"Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014", "May 2014",
"Jun 2014")), `39` = structure(c("0.074822001", "-1.258324027",
"1.153113008", "1.344225049", "2.703722954", "-1.334722042",
"1.17830801", "1.126680017", "", "", "", ""), .Names = c("Aug 2013",
"Sep 2013", "Oct 2013", "Nov 2013", "Dec 2013", "Jan 2014",
"Feb 2014", "Mar 2014", "Apr 2014", "May 2014", "Jun 2014",
"Jul 2014")), `40` = structure(c("-1.258324027", "1.153113008",
"1.344225049", "2.703722954", "-1.334722042", "1.17830801",
"1.126680017", "", "", "", "", ""), .Names = c("Sep 2013",
"Oct 2013", "Nov 2013", "Dec 2013", "Jan 2014", "Feb 2014",
"Mar 2014", "Apr 2014", "May 2014", "Jun 2014", "Jul 2014",
"Aug 2014")), `41` = structure(c("1.153113008", "1.344225049",
"2.703722954", "-1.334722042", "1.17830801", "1.126680017",
"", "", "", "", "", ""), .Names = c("Oct 2013", "Nov 2013",
"Dec 2013", "Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014",
"May 2014", "Jun 2014", "Jul 2014", "Aug 2014", "Sep 2014"
)), `42` = structure(c("1.344225049", "2.703722954", "-1.334722042",
"1.17830801", "1.126680017", "", "", "", "", "", "", ""), .Names = c("Nov 2013",
"Dec 2013", "Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014",
"May 2014", "Jun 2014", "Jul 2014", "Aug 2014", "Sep 2014",
"Oct 2014")), `43` = structure(c("2.703722954", "-1.334722042",
"1.17830801", "1.126680017", "", "", "", "", "", "", "",
""), .Names = c("Dec 2013", "Jan 2014", "Feb 2014", "Mar 2014",
"Apr 2014", "May 2014", "Jun 2014", "Jul 2014", "Aug 2014",
"Sep 2014", "Oct 2014", "Nov 2014")), `44` = structure(c("-1.334722042",
"1.17830801", "1.126680017", "", "", "", "", "", "", "",
"", ""), .Names = c("Jan 2014", "Feb 2014", "Mar 2014", "Apr 2014",
"May 2014", "Jun 2014", "Jul 2014", "Aug 2014", "Sep 2014",
"Oct 2014", "Nov 2014", "Dec 2014")), `45` = structure(c("1.17830801",
"1.126680017", "", "", "", "", "", "", "", "", ""), .Names = c("Feb 2014",
"Mar 2014", "Apr 2014", "May 2014", "Jun 2014", "Jul 2014",
"Aug 2014", "Sep 2014", "Oct 2014", "Nov 2014", "Dec 2014"
)), `46` = structure(c("1.126680017", "", "", "", "", "",
"", "", "", ""), .Names = c("Mar 2014", "Apr 2014", "May 2014",
"Jun 2014", "Jul 2014", "Aug 2014", "Sep 2014", "Oct 2014",
"Nov 2014", "Dec 2014")), `47` = structure(c("0.297455013",
"-2.498219013", "-1.982529998", "0.710475028", "2.43479991",
"-1.629583001", "3.825987101", "1.375319004", "0.468528003",
"-1.180858016", "-0.791706979", "0.260260999"), .Names = c("Sep 2005",
"Oct 2005", "Nov 2005", "Dec 2005", "Jan 2006", "Feb 2006",
"Mar 2006", "Apr 2006", "May 2006", "Jun 2006", "Jul 2006",
"Aug 2006")), `48` = structure(c("-2.498219013", "-1.982529998",
"0.710475028", "2.43479991", "-1.629583001", "3.825987101",
"1.375319004", "0.468528003", "-1.180858016", "-0.791706979",
"0.260260999", "1.613098025"), .Names = c("Oct 2005", "Nov 2005",
"Dec 2005", "Jan 2006", "Feb 2006", "Mar 2006", "Apr 2006",
"May 2006", "Jun 2006", "Jul 2006", "Aug 2006", "Sep 2006"
)), `49` = structure(c("-1.982529998", "0.710475028", "2.43479991",
"-1.629583001", "3.825987101", "1.375319004", "0.468528003",
"-1.180858016", "-0.791706979", "0.260260999", "1.613098025",
"0.493414998"), .Names = c("Nov 2005", "Dec 2005", "Jan 2006",
"Feb 2006", "Mar 2006", "Apr 2006", "May 2006", "Jun 2006",
"Jul 2006", "Aug 2006", "Sep 2006", "Oct 2006")), `50` = structure(c("0.710475028",
"2.43479991", "-1.629583001", "3.825987101", "1.375319004",
"0.468528003", "-1.180858016", "-0.791706979", "0.260260999",
"1.613098025", "0.493414998", "0.659148991"), .Names = c("Dec 2005",
"Jan 2006", "Feb 2006", "Mar 2006", "Apr 2006", "May 2006",
"Jun 2006", "Jul 2006", "Aug 2006", "Sep 2006", "Oct 2006",
"Nov 2006"))), .Names = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
"41", "42", "43", "44", "45", "46", "47", "48", "49", "50"))
Вы хотите сохранить атрибут имени, связанный с номером, или просто хотите сохранить номер? Как и в случае «-3.531716108» имеет атрибут имени «Май 2012» – rsoren
Только цифры, так как это будет идеально просто в стандартизованной фрейме n * 12 –
Первая проблема, с которой вы столкнулись, - это 12-ти столбцовый фрейм, не имеет особого смысла так как каждый список захватывает 12 месяцев вперед. Поэтому, если вы ограничили это до 12 столбцов, вы бы, скажем, в июне 2013 года, так же, как и в июне 2014 года, учитывая концептуальную структуру, о которой я думал, чтобы ответить на ваш вопрос. –