Создание таблицы, суммирующей общее количество экземпляров или вывод 0

#r

#r

Вопрос:

Я пытаюсь создать таблицу, в которой будут отображаться почтовые индексы в Чикаго вместе с общим количеством еженедельных смертей на почтовый индекс. Я использую следующее

 DeathsWeekly <- Chicago_Final$Deaths...Weekly
table(Chicago_Final$ZIP,DeathsWeekly)
 

При этом текущем выводе почтовые индексы отображаются правильно, но общее количество смертей не отображается. Что я получаю, так это количество одиночных смертей, двойных смертей, выровненных по столбцам и т. Д… но мне это нужно, чтобы показать общее количество смертей по почтовому индексу. Например, мне нужно, чтобы она отображала Zip 60601, общее количество смертей 5, а если в почтовом индексе не было смертей 0.

Я прикрепил изображение моего вывода для лучшего ознакомления.

Вывод

 dput(head(Chicago_Final,100))
structure(list(...1 = 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, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 
77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 
93, 94, 95, 96, 97, 98, 99, 100), ZIP = c(60601, 60601, 60601, 
60601, 60601, 60601, 60601, 60601, 60601, 60601, 60601, 60601, 
60601, 60602, 60602, 60602, 60602, 60602, 60602, 60602, 60602, 
60602, 60602, 60602, 60602, 60602, 60603, 60603, 60603, 60603, 
60603, 60603, 60603, 60603, 60603, 60603, 60603, 60603, 60603, 
60604, 60604, 60604, 60604, 60604, 60604, 60604, 60604, 60604, 
60604, 60604, 60604, 60604, 60605, 60605, 60605, 60605, 60605, 
60605, 60605, 60605, 60605, 60605, 60605, 60605, 60605, 60606, 
60606, 60606, 60606, 60606, 60606, 60606, 60606, 60606, 60606, 
60606, 60606, 60606, 60607, 60607, 60607, 60607, 60607, 60607, 
60607, 60607, 60607, 60607, 60607, 60607, 60607, 60608, 60608, 
60608, 60608, 60608, 60608, 60608, 60608, 60608), Week.Number = c(20, 
18, 21, 14, 17, 19, 15, 16, 10, 11, 13, 22, 12, 17, 13, 22, 20, 
10, 19, 21, 12, 15, 18, 14, 11, 16, 19, 22, 14, 17, 12, 16, 15, 
18, 13, 10, 20, 11, 21, 18, 20, 11, 17, 13, 12, 19, 10, 15, 22, 
14, 21, 16, 16, 12, 11, 14, 20, 18, 10, 21, 15, 19, 22, 13, 17, 
12, 15, 11, 20, 13, 14, 16, 10, 19, 17, 22, 21, 18, 16, 12, 10, 
13, 14, 22, 19, 11, 21, 17, 15, 18, 20, 18, 20, 16, 14, 19, 15, 
10, 13, 17), Cases...Weekly = c("4", "13", "1", "7", "5", "8", 
"6", "4", "NA", "NA", "9", "2", "8", "2", "NA", "2", "1", "NA", 
"3", "2", "NA", "NA", "0", "NA", "NA", "NA", "0", "2", "NA", 
"NA", "NA", "NA", "NA", "2", "NA", "NA", "0", "NA", "1", "3", 
"3", "NA", "2", "NA", "NA", "5", "NA", "NA", "2", "NA", "1", 
"NA", "26", "14", "NA", "16", "9", "17", "NA", "12", "12", "12", 
"13", "15", "27", "NA", "2", "NA", "2", "NA", "2", "10", "NA", 
"5", "8", "5", "2", "2", "34", "11", "NA", "24", "36", "3", "17", 
"NA", "18", "17", "205", "41", "13", "292", "196", "120", "91", 
"266", "123", "NA", "60", "183"), Cases...Cumulative = c("67", 
"55", "68", "27", "42", "63", "33", "37", "NA", "NA", "20", "70", 
"11", "5", "NA", "13", "9", "NA", "8", "11", "NA", "NA", "5", 
"NA", "NA", "NA", "5", "8", "NA", "NA", "NA", "NA", "NA", "5", 
"NA", "NA", "5", "NA", "6", "9", "17", "NA", "6", "NA", "NA", 
"14", "NA", "NA", "20", "NA", "18", "NA", "85", "16", "NA", "47", 
"150", "129", "NA", "162", "59", "141", "175", "31", "112", "NA", 
"7", "NA", "34", "NA", "5", "17", "NA", "32", "25", "41", "36", 
"27", "310", "11", "NA", "35", "71", "419", "385", "NA", "416", 
"327", "276", "368", "398", "875", "1337", "400", "157", "1141", 
"280", "NA", "66", "583"), Case.Rate...Weekly = c("27", "89", 
"7", "48", "34", "54", "41", "27", "NA", "NA", "61", "14", "54", 
"161", "NA", "161", "80", "NA", "241", "161", "NA", "NA", "0", 
"NA", "NA", "NA", "0", "170", "NA", "NA", "NA", "NA", "NA", "170", 
"NA", "NA", "0", "NA", "85", "384", "384", "NA", "256", "NA", 
"NA", "639", "NA", "NA", "256", "NA", "128", "NA", "94", "51", 
"NA", "58", "33", "62", "NA", "44", "44", "44", "47", "54", "98", 
"NA", "64", "NA", "64", "NA", "64", "322", "NA", "161", "258", 
"161", "64", "64", "115", "37", "NA", "81", "122", "10", "57", 
"NA", "61", "57", "693", "139", "44", "369", "248", "152", "115", 
"336", "155", "NA", "76", "231"), Case.Rate...Cumulative = c("456.6", 
"374.8", "463.4", "184", "286.2", "429.3", "224.9", "252.1", 
"NA", "NA", "136.30000000000001", "477", "75", "401.9", "NA", 
"1045", "723.5", "NA", "643.1", "884.2", "NA", "NA", "401.9", 
"NA", "NA", "NA", "425.9", "681.4", "NA", "NA", "NA", "NA", "NA", 
"425.9", "NA", "NA", "425.9", "NA", "511.1", "1150.9000000000001", 
"2173.9", "NA", "767.3", "NA", "NA", "1790.3", "NA", "NA", "2557.5", 
"NA", "2301.8000000000002", "NA", "308.89999999999998", "58.1", 
"NA", "170.8", "545.1", "468.8", "NA", "588.70000000000005", 
"214.4", "512.4", "635.9", "112.6", "407", "NA", "225.7", "NA", 
"1096.4000000000001", "NA", "161.19999999999999", "548.20000000000005", 
"NA", "1031.9000000000001", "806.2", "1322.2", "1160.9000000000001", 
"870.7", "1047.5999999999999", "37.200000000000003", "NA", "118.3", 
"239.9", "1416", "1301.0999999999999", "NA", "1405.8", "1105.0999999999999", 
"932.7", "1243.5999999999999", "1345", "1104.7", "1688", "505", 
"198.2", "1440.6", "353.5", "NA", "83.3", "736.1"), Tests...Weekly = c(79, 
71, 79, 22, 48, 78, 39, 41, 1, 7, 39, 90, 33, 14, 3, 21, 13, 
0, 16, 17, 3, 3, 5, 4, 0, 10, 5, 6, 4, 3, 1, 3, 5, 10, 3, 0, 
5, 0, 14, 14, 13, 0, 10, 7, 0, 12, 0, 1, 15, 3, 10, 3, 107, 83, 
17, 66, 145, 160, 0, 183, 89, 141, 207, 84, 110, 15, 28, 3, 81, 
15, 11, 31, 0, 45, 39, 116, 72, 35, 122, 73, 0, 120, 91, 182, 
166, 8, 198, 231, 287, 137, 181, 962, 748, 364, 191, 757, 322, 
2, 201, 495), Tests...Cumulative = c(458, 301, 537, 102, 230, 
379, 141, 182, 1, 8, 80, 627, 41, 37, 6, 109, 71, 0, 58, 88, 
3, 13, 42, 10, 0, 23, 34, 59, 8, 19, 1, 16, 13, 29, 4, 0, 39, 
0, 53, 38, 63, 0, 24, 7, 0, 50, 0, 11, 88, 10, 73, 14, 446, 100, 
17, 250, 1002, 716, 0, 1185, 339, 857, 1392, 184, 556, 18, 72, 
3, 303, 33, 44, 103, 0, 222, 142, 491, 375, 177, 701, 81, 0, 
201, 292, 1796, 1235, 8, 1614, 932, 579, 1069, 1416, 2632, 4137, 
1175, 489, 3389, 811, 2, 298, 1670), Test.Rate...Weekly = c(538, 
484, 538, 150, 327, 532, 266, 279, 7, 48, 266, 613, 225, 1125, 
241, 1688, 1045, 0, 1286, 1367, 241, 241, 402, 322, 0, 804, 426, 
511, 341, 256, 85, 256, 426, 852, 256, 0, 426, 0, 1192, 1790, 
1662, 0, 1279, 895, 0, 1534, 0, 128, 1918, 384, 1279, 384, 389, 
302, 62, 240, 527, 581, 0, 665, 323, 512, 752, 305, 400, 484, 
903, 97, 2612, 484, 355, 1000, 0, 1451, 1258, 3741, 2322, 1129, 
412, 247, 0, 406, 308, 615, 561, 27, 669, 781, 970, 463, 612, 
1215, 944, 460, 241, 956, 406, 2, 254, 625), Test.Rate...Cumulative = c(3121, 
2051.1, 3659.3, 695.1, 1567.3, 2582.6, 960.8, 1240.2, 6.8, 54.5, 
545.1, 4272.6, 279.4, 2974.3, 482.3, 8762.1, 5707.4, 0, 4662.4, 
7074, 241.2, 1045, 3376.2, 803.9, 0, 1848.9, 2896.1, 5025.6, 
681.4, 1618.4, 85.2, 1362.9, 1107.3, 2470.2, 340.7, 0, 3322, 
0, 4514.5, 4859.3, 8056.3, 0, 3069.1, 895.1, 0, 6393.9, 0, 1406.6, 
11253.2, 1278.8, 9335, 1790.3, 1620.7, 363.4, 61.8, 908.5, 3641.1, 
2601.8, 0, 4306.1, 1231.9, 3114.2, 5058.3, 668.6, 2020.4, 580.5, 
2321.8, 96.7, 9771, 1064.2, 1418.9, 3321.5, 0, 7159, 4579.2, 
15833.6, 12092.9, 5707.8, 2369, 273.7, 0, 679.3, 986.8, 6069.4, 
4173.6, 27, 5454.4, 3149.6, 1956.7, 3612.6, 4785.2, 3323, 5223.2, 
1483.5, 617.4, 4278.8, 1023.9, 2.5, 376.2, 2108.5), Percent.Tested.Positive...Weekly = c("0", 
"0.2", "0", "0.2", "0.1", "0.1", "0.2", "0.1", "NA", "NA", "0.2", 
"0", "0.3", "0", "NA", "0", "0.1", "NA", "0.2", "0.2", "NA", 
"NA", "0", "NA", "NA", "0.2", "0", "0.2", "NA", "NA", "NA", "NA", 
"NA", "0.1", "NA", "NA", "0.2", "NA", "0.1", "0.4", "0.2", "NA", 
"0.2", "NA", "NA", "0.2", "NA", "NA", "0.1", "NA", "0.2", "NA", 
"0.3", "0.2", "NA", "0.2", "0", "0.1", "NA", "0.1", "0.2", "0.1", 
"0.1", "0.2", "0.2", "NA", "0.1", "NA", "0", "NA", "0.1", "0.4", 
"NA", "0.1", "0.2", "0", "0", "0.1", "0.3", "0.2", "NA", "0.2", 
"0.4", "0", "0.1", "NA", "0.1", "0.1", "0.7", "0.3", "0.1", "0.4", 
"0.2", "0.3", "0.4", "0.3", "0.4", "NA", "0.4", "0.4"), Percent.Tested.Positive...Cumulative = c("0.1", 
"0.2", "0.1", "0.3", "0.2", "0.2", "0.2", "0.2", "NA", "NA", 
"0.3", "0.1", "0.3", "0.1", "NA", "0.1", "0.1", "NA", "0.1", 
"0.1", "NA", "NA", "0.1", "NA", "NA", "0.2", "0.1", "0.1", "NA", 
"NA", "NA", "NA", "NA", "0.2", "NA", "NA", "0.2", "NA", "0.1", 
"0.3", "0.3", "NA", "0.2", "NA", "NA", "0.3", "NA", "NA", "0.2", 
"NA", "0.3", "NA", "0.2", "0.2", "NA", "0.2", "0.2", "0.2", "NA", 
"0.1", "0.2", "0.2", "0.1", "0.2", "0.2", "NA", "0.1", "NA", 
"0.1", "NA", "0.1", "0.2", "NA", "0.1", "0.2", "0.1", "0.1", 
"0.2", "0.4", "0.2", "NA", "0.2", "0.3", "0.2", "0.3", "NA", 
"0.3", "0.4", "0.5", "0.3", "0.3", "0.4", "0.3", "0.4", "0.4", 
"0.3", "0.4", "NA", "0.3", "0.4"), Deaths...Weekly = c(0, 1, 
0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 
0, 2, 1, 1, 0, 10, 4, 6, 1, 8, 3, 0, 0, 6), Deaths...Cumulative = c(5, 
4, 5, 0, 3, 5, 1, 2, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 
0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 2, 2, 2, 1, 0, 0, 0, 0, 5, 5, 
0, 5, 3, 1, 4, 5, 26, 38, 10, 1, 34, 4, 0, 0, 16), Death.Rate...Weekly = c(0, 
6.8, 0, 0, 6.8, 6.8, 6.8, 6.8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.6, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64.5, 0, 
0, 0, 0, 0, 0, 3.4, 0, 0, 6.8, 3.4, 3.4, 0, 12.6, 5.1, 7.6, 1.3, 
10.1, 3.8, 0, 0, 7.6), Death.Rate...Cumulative = c(34.1, 27.3, 
34.1, 0, 20.4, 34.1, 6.8, 13.6, 0, 0, 0, 34.1, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.6, 3.6, 
0, 3.6, 0, 3.6, 3.6, 0, 0, 0, 0, 0, 64.5, 0, 0, 0, 0, 64.5, 0, 
64.5, 64.5, 64.5, 3.4, 0, 0, 0, 0, 16.9, 16.9, 0, 16.9, 10.1, 
3.4, 13.5, 16.9, 32.8, 48, 12.6, 1.3, 42.9, 5.1, 0, 0, 20.2), 
    Population.x = c(14675, 14675, 14675, 14675, 14675, 14675, 
    14675, 14675, 14675, 14675, 14675, 14675, 14675, 1244, 1244, 
    1244, 1244, 1244, 1244, 1244, 1244, 1244, 1244, 1244, 1244, 
    1244, 1174, 1174, 1174, 1174, 1174, 1174, 1174, 1174, 1174, 
    1174, 1174, 1174, 1174, 782, 782, 782, 782, 782, 782, 782, 
    782, 782, 782, 782, 782, 782, 27519, 27519, 27519, 27519, 
    27519, 27519, 27519, 27519, 27519, 27519, 27519, 27519, 27519, 
    3101, 3101, 3101, 3101, 3101, 3101, 3101, 3101, 3101, 3101, 
    3101, 3101, 3101, 29591, 29591, 29591, 29591, 29591, 29591, 
    29591, 29591, 29591, 29591, 29591, 29591, 29591, 79205, 79205, 
    79205, 79205, 79205, 79205, 79205, 79205, 79205), `Location (North, West)` = c("41.885805, -87.622911", 
    "41.885805, -87.622911", "41.885805, -87.622911", "41.885805, -87.622911", 
    "41.885805, -87.622911", "41.885805, -87.622911", "41.885805, -87.622911", 
    "41.885805, -87.622911", "41.885805, -87.622911", "41.885805, -87.622911", 
    "41.885805, -87.622911", "41.885805, -87.622911", "41.885805, -87.622911", 
    "41.883067, -87.629187", "41.883067, -87.629187", "41.883067, -87.629187", 
    "41.883067, -87.629187", "41.883067, -87.629187", "41.883067, -87.629187", 
    "41.883067, -87.629187", "41.883067, -87.629187", "41.883067, -87.629187", 
    "41.883067, -87.629187", "41.883067, -87.629187", "41.883067, -87.629187", 
    "41.883067, -87.629187", "41.880614, -87.629311", "41.880614, -87.629311", 
    "41.880614, -87.629311", "41.880614, -87.629311", "41.880614, -87.629311", 
    "41.880614, -87.629311", "41.880614, -87.629311", "41.880614, -87.629311", 
    "41.880614, -87.629311", "41.880614, -87.629311", "41.880614, -87.629311", 
    "41.880614, -87.629311", "41.880614, -87.629311", "41.878266, -87.626150", 
    "41.878266, -87.626150", "41.878266, -87.626150", "41.878266, -87.626150", 
    "41.878266, -87.626150", "41.878266, -87.626150", "41.878266, -87.626150", 
    "41.878266, -87.626150", "41.878266, -87.626150", "41.878266, -87.626150", 
    "41.878266, -87.626150", "41.878266, -87.626150", "41.878266, -87.626150", 
    "41.857651, -87.615592", "41.857651, -87.615592", "41.857651, -87.615592", 
    "41.857651, -87.615592", "41.857651, -87.615592", "41.857651, -87.615592", 
    "41.857651, -87.615592", "41.857651, -87.615592", "41.857651, -87.615592", 
    "41.857651, -87.615592", "41.857651, -87.615592", "41.857651, -87.615592", 
    "41.857651, -87.615592", "41.881988, -87.637329", "41.881988, -87.637329", 
    "41.881988, -87.637329", "41.881988, -87.637329", "41.881988, -87.637329", 
    "41.881988, -87.637329", "41.881988, -87.637329", "41.881988, -87.637329", 
    "41.881988, -87.637329", "41.881988, -87.637329", "41.881988, -87.637329", 
    "41.881988, -87.637329", "41.881988, -87.637329", "41.874503, -87.651322", 
    "41.874503, -87.651322", "41.874503, -87.651322", "41.874503, -87.651322", 
    "41.874503, -87.651322", "41.874503, -87.651322", "41.874503, -87.651322", 
    "41.874503, -87.651322", "41.874503, -87.651322", "41.874503, -87.651322", 
    "41.874503, -87.651322", "41.874503, -87.651322", "41.874503, -87.651322", 
    "41.848647, -87.672320", "41.848647, -87.672320", "41.848647, -87.672320", 
    "41.848647, -87.672320", "41.848647, -87.672320", "41.848647, -87.672320", 
    "41.848647, -87.672320", "41.848647, -87.672320", "41.848647, -87.672320"
    ), `HH Avg Income` = c(77374, 77374, 77374, 77374, 77374, 
    77374, 77374, 77374, 77374, 77374, 77374, 77374, 77374, 23750, 
    23750, 23750, 23750, 23750, 23750, 23750, 23750, 23750, 23750, 
    23750, 23750, 23750, 61815, 61815, 61815, 61815, 61815, 61815, 
    61815, 61815, 61815, 61815, 61815, 61815, 61815, 31250, 31250, 
    31250, 31250, 31250, 31250, 31250, 31250, 31250, 31250, 31250, 
    31250, 31250, 56151, 56151, 56151, 56151, 56151, 56151, 56151, 
    56151, 56151, 56151, 56151, 56151, 56151, 100377, 100377, 
    100377, 100377, 100377, 100377, 100377, 100377, 100377, 100377, 
    100377, 100377, 100377, 40972, 40972, 40972, 40972, 40972, 
    40972, 40972, 40972, 40972, 40972, 40972, 40972, 40972, 28026, 
    28026, 28026, 28026, 28026, 28026, 28026, 28026, 28026), 
    dptt = c(3.40715502555366, 2.72572402044293, 3.40715502555366, 
    0, 2.0442930153322, 3.40715502555366, 0.681431005110733, 
    1.36286201022147, 0, 0, 0, 3.40715502555366, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0.363385297430866, 0.363385297430866, 0, 0.363385297430866, 
    0, 0.363385297430866, 0.363385297430866, 0, 0, 0, 0, 0, 6.44953240890035, 
    0, 0, 0, 0, 6.44953240890035, 0, 6.44953240890035, 6.44953240890035, 
    6.44953240890035, 0.33794059004427, 0, 0, 0, 0, 1.68970295022135, 
    1.68970295022135, 0, 1.68970295022135, 1.01382177013281, 
    0.33794059004427, 1.35176236017708, 1.68970295022135, 3.2826210466511, 
    4.79767691433622, 1.26254655640427, 0.126254655640427, 4.29265829177451, 
    0.505018622561707, 0, 0, 2.02007449024683), people.sqmi = c("35", 
    "35", "35", "35", "35", "35", "35", "35", "35", "35", "35", 
    "35", "35", "3", "3", "3", "3", "3", "3", "3", "3", "3", 
    "3", "3", "3", "3", "5", "5", "5", "5", "5", "5", "5", "5", 
    "5", "5", "5", "5", "5", "2", "2", "2", "2", "2", "2", "2", 
    "2", "2", "2", "2", "2", "2", "8", "8", "8", "8", "8", "8", 
    "8", "8", "8", "8", "8", "8", "8", "9", "9", "9", "9", "9", 
    "9", "9", "9", "9", "9", "9", "9", "9", "10", "10", "10", 
    "10", "10", "10", "10", "10", "10", "10", "10", "10", "10", 
    "30", "30", "30", "30", "30", "30", "30", "30", "30")), row.names = c(NA, 
-100L), class = c("tbl_df", "tbl", "data.frame"))
 

Комментарии:

1. Пожалуйста, используйте dput(head(Chicago_Final,100)) и вставьте вывод в свой вопрос и не используйте снимки экрана, поскольку мы не сможем вам помочь!

2. Я скопировал вставленный результат

3. Вы хотите aggregate(Deaths...Weekly~ZIP, Chicago_Final,sum, na.rm = TRUE) ?

4. это именно то, что я искал!

Ответ №1:

Попробуйте что-то подобное, используя и устанавливая tidyverse пакет:

 library(tidyverse)
#Code
new <- Chicago_Final %>% select(c(ZIP,Week.Number,Deaths...Weekly)) %>%
  pivot_wider(names_from = Week.Number,values_from=Deaths...Weekly,
              values_fill=0)
 

Вывод:

 # A tibble: 8 x 14
    ZIP  `20`  `18`  `21`  `14`  `17`  `19`  `15`  `16`  `10`  `11`  `13`  `22`  `12`
  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 60601     0     1     0     0     1     1     1     1     0     0     0     0     0
2 60602     0     0     0     0     0     0     0     0     0     0     0     0     0
3 60603     0     0     0     0     0     0     0     0     0     0     0     0     0
4 60604     0     0     0     0     0     0     0     0     0     0     0     0     0
5 60605     0     1     0     0     0     0     0     0     0     0     0     0     0
6 60606     0     2     0     0     0     0     0     0     0     0     0     0     0
7 60607     0     1     0     0     2     1     1     0     0     0     0     0     0
8 60608     4    10     0     1     6     8     3     6     0     0     0     0     0