Split issue with model_time and timetk in R - r

I'm using modeltime to forecast 20 time series (not balanced) at once using Modeltime package. However, when I call the function modeltime_calibrate i got the following error:
Error in glubort(): ! Missing 'new_data'. Try adding a test data set
using rsample::testing(splits). See help for more info:
?modeltime_calibrate
Its seems to be related to split, but I couldn't find any explanation:
splits <Analysis/Assess/Total> <887/20/907>
Follow my code.
Thanks,
Rick
splits <- data %>% time_series_split(assess = "3 months", cumulative = TRUE)
splits %>%
tk_time_series_cv_plan() %>%
plot_time_series_cv_plan(date, value, .interactive = TRUE)
rec_obj <- recipe(value ~ ., training(splits)) %>%
step_mutate(ID = droplevels(ID)) %>%
step_timeseries_signature(date) %>%
step_rm(date) %>%
step_zv(all_predictors()) %>%
step_dummy(all_nominal_predictors(), one_hot = TRUE)
summary(prep(rec_obj))
wflw_xgb <- workflow() %>%
add_model(
boost_tree() %>% set_engine("xgboost")
) %>%
add_recipe(rec_obj) %>%
fit(training(splits))
wflw_xgb
model_tbl <- modeltime_table(
wflw_xgb
)
model_tbl
calib_tbl <- model_tbl %>%
modeltime_calibrate(
new_data = testing(splits),
id = "ID",
modeltime_calibrate(quiet = FALSE)
)
calib_tbl
Data:
dput(data2)
structure(list(date = structure(c(1609459200, 1612137600, 1614556800,
1617235200, 1619827200, 1622505600, 1625097600, 1627776000, 1630454400,
1633046400, 1635724800, 1638316800, 1640995200, 1643673600, 1646092800,
1648771200, 1651363200, 1609459200, 1612137600, 1614556800, 1617235200,
1619827200, 1622505600, 1625097600, 1627776000, 1630454400, 1633046400,
1635724800, 1638316800, 1640995200, 1643673600, 1646092800, 1648771200,
1651363200, 1609459200, 1612137600, 1614556800, 1617235200, 1619827200,
1622505600, 1625097600, 1627776000, 1630454400, 1633046400, 1635724800,
1638316800, 1640995200, 1643673600, 1646092800, 1648771200, 1651363200,
1420070400, 1422748800, 1425168000, 1427846400, 1430438400, 1433116800,
1435708800, 1438387200, 1441065600, 1443657600, 1446336000, 1448928000,
1451606400, 1454284800, 1456790400, 1459468800, 1462060800, 1464739200,
1467331200, 1470009600, 1472688000, 1475280000, 1477958400, 1480550400,
1483228800, 1485907200, 1488326400, 1491004800, 1493596800, 1496275200,
1498867200, 1501545600, 1504224000, 1506816000, 1509494400, 1512086400,
1514764800, 1517443200, 1519862400, 1522540800, 1525132800, 1527811200,
1530403200, 1533081600, 1535760000, 1538352000, 1541030400, 1543622400,
1546300800, 1548979200, 1551398400, 1554076800, 1556668800, 1559347200,
1561939200, 1564617600, 1567296000, 1569888000, 1572566400, 1575158400,
1577836800, 1580515200, 1583020800, 1585699200, 1588291200, 1590969600,
1593561600, 1596240000, 1598918400, 1601510400, 1604188800, 1606780800,
1609459200, 1612137600, 1614556800, 1617235200, 1619827200, 1622505600,
1625097600, 1627776000, 1630454400, 1633046400, 1635724800, 1638316800,
1640995200, 1643673600, 1646092800, 1648771200, 1651363200, 1609459200,
1612137600, 1614556800, 1617235200, 1619827200, 1622505600, 1625097600,
1627776000, 1630454400, 1633046400, 1635724800, 1638316800, 1640995200,
1643673600, 1646092800, 1648771200, 1651363200, 1506816000, 1509494400,
1512086400, 1514764800, 1517443200, 1519862400, 1522540800, 1525132800,
1527811200, 1530403200, 1533081600, 1535760000, 1538352000, 1541030400,
1543622400, 1546300800, 1548979200, 1551398400, 1554076800, 1556668800,
1559347200, 1561939200, 1564617600, 1567296000, 1569888000, 1572566400,
1575158400, 1577836800, 1580515200, 1583020800, 1585699200, 1588291200,
1590969600, 1593561600, 1596240000, 1598918400, 1601510400, 1604188800,
1606780800, 1609459200, 1612137600, 1614556800, 1617235200, 1619827200,
1622505600, 1625097600, 1627776000, 1630454400, 1633046400, 1635724800,
1638316800, 1640995200, 1643673600, 1646092800, 1648771200, 1651363200,
1533081600, 1535760000, 1538352000, 1541030400, 1543622400, 1546300800,
1548979200, 1551398400, 1554076800, 1556668800, 1559347200, 1561939200,
1564617600, 1567296000, 1569888000, 1572566400, 1575158400, 1577836800,
1580515200, 1583020800, 1585699200, 1588291200, 1590969600, 1593561600,
1596240000, 1598918400, 1601510400, 1604188800, 1606780800, 1609459200,
1612137600, 1614556800, 1617235200, 1619827200, 1622505600, 1625097600,
1627776000, 1630454400, 1633046400, 1635724800, 1638316800, 1640995200,
1643673600, 1646092800, 1648771200, 1651363200, 1420070400, 1422748800,
1425168000, 1598918400, 1601510400, 1604188800, 1606780800, 1609459200,
1612137600, 1614556800, 1617235200, 1619827200, 1622505600, 1625097600,
1627776000, 1630454400, 1633046400, 1635724800, 1638316800, 1640995200,
1643673600, 1646092800, 1648771200, 1651363200, 1609459200, 1612137600,
1614556800, 1617235200, 1619827200, 1622505600, 1625097600, 1627776000,
1630454400, 1633046400, 1635724800, 1638316800, 1640995200, 1643673600,
1646092800, 1648771200, 1651363200, 1630454400, 1633046400, 1635724800,
1638316800, 1640995200, 1643673600, 1646092800, 1648771200, 1651363200,
1614556800, 1617235200, 1619827200, 1622505600, 1625097600, 1627776000,
1630454400, 1633046400, 1635724800, 1638316800, 1640995200, 1643673600,
1646092800, 1648771200, 1651363200, 1609459200, 1612137600, 1614556800,
1617235200, 1619827200, 1622505600, 1625097600, 1627776000, 1630454400,
1633046400, 1635724800, 1638316800, 1640995200, 1643673600, 1646092800,
1648771200, 1651363200, 1480550400, 1483228800, 1485907200, 1488326400,
1491004800, 1493596800, 1496275200, 1498867200, 1501545600, 1504224000,
1506816000, 1509494400, 1512086400, 1514764800, 1517443200, 1519862400,
1522540800, 1525132800, 1527811200, 1530403200, 1533081600, 1535760000,
1538352000, 1541030400, 1543622400, 1546300800, 1548979200, 1551398400,
1554076800, 1556668800, 1559347200, 1561939200, 1564617600, 1567296000,
1569888000, 1572566400, 1575158400, 1577836800, 1580515200, 1583020800,
1585699200, 1588291200, 1590969600, 1593561600, 1596240000, 1598918400,
1601510400, 1604188800, 1606780800, 1609459200, 1612137600, 1614556800,
1617235200, 1619827200, 1622505600, 1625097600, 1627776000, 1630454400,
1633046400, 1635724800, 1638316800, 1640995200, 1643673600, 1646092800,
1648771200, 1651363200, 1420070400, 1422748800, 1425168000, 1427846400,
1430438400, 1433116800, 1435708800, 1438387200, 1441065600, 1443657600,
1446336000, 1448928000, 1451606400, 1454284800, 1456790400, 1459468800,
1462060800, 1464739200, 1467331200, 1470009600, 1472688000, 1475280000,
1477958400, 1480550400, 1483228800, 1485907200, 1488326400, 1491004800,
1493596800, 1496275200, 1498867200, 1501545600, 1504224000, 1506816000,
1509494400, 1512086400, 1514764800, 1517443200, 1519862400, 1522540800,
1525132800, 1527811200, 1530403200, 1533081600, 1535760000, 1538352000,
1541030400, 1543622400, 1546300800, 1548979200, 1551398400, 1554076800,
1556668800, 1559347200, 1561939200, 1564617600, 1567296000, 1569888000,
1572566400, 1575158400, 1577836800, 1580515200, 1583020800, 1585699200,
1588291200, 1590969600, 1593561600, 1596240000, 1598918400, 1601510400,
1604188800, 1606780800, 1609459200, 1612137600, 1614556800, 1617235200,
1619827200, 1622505600, 1625097600, 1627776000, 1630454400, 1633046400,
1635724800, 1638316800, 1640995200, 1643673600, 1646092800, 1648771200,
1651363200, 1604188800, 1606780800, 1609459200, 1612137600, 1614556800,
1617235200, 1619827200, 1622505600, 1625097600, 1627776000, 1630454400,
1633046400, 1635724800, 1638316800, 1640995200, 1643673600, 1646092800,
1648771200, 1651363200, 1420070400, 1422748800, 1425168000, 1427846400,
1430438400, 1433116800, 1435708800, 1438387200, 1441065600, 1443657600,
1446336000, 1448928000, 1451606400, 1454284800, 1456790400, 1459468800,
1462060800, 1464739200, 1467331200, 1470009600, 1472688000, 1475280000,
1477958400, 1480550400, 1483228800, 1485907200, 1488326400, 1491004800,
1493596800, 1496275200, 1498867200, 1501545600, 1504224000, 1506816000,
1509494400, 1512086400, 1514764800, 1517443200, 1519862400, 1522540800,
1525132800, 1527811200, 1530403200, 1533081600, 1535760000, 1538352000,
1541030400, 1543622400, 1546300800, 1548979200, 1551398400, 1554076800,
1556668800, 1559347200, 1561939200, 1564617600, 1567296000, 1569888000,
1572566400, 1575158400, 1577836800, 1580515200, 1583020800, 1585699200,
1588291200, 1590969600, 1593561600, 1596240000, 1598918400, 1601510400,
1604188800, 1606780800, 1609459200, 1612137600, 1614556800, 1617235200,
1619827200, 1622505600, 1625097600, 1627776000, 1630454400, 1633046400,
1635724800, 1638316800, 1640995200, 1643673600, 1646092800, 1648771200,
1651363200, 1420070400, 1422748800, 1425168000, 1427846400, 1430438400,
1433116800, 1435708800, 1438387200, 1441065600, 1443657600, 1446336000,
1448928000, 1451606400, 1454284800, 1456790400, 1459468800, 1462060800,
1464739200, 1467331200, 1470009600, 1472688000, 1475280000, 1477958400,
1480550400, 1483228800, 1485907200, 1488326400, 1491004800, 1493596800,
1496275200, 1498867200, 1501545600, 1504224000, 1506816000, 1509494400,
1512086400, 1514764800, 1517443200, 1519862400, 1522540800, 1525132800,
1527811200, 1530403200, 1533081600, 1535760000, 1538352000, 1541030400,
1543622400, 1546300800, 1548979200, 1551398400, 1554076800, 1556668800,
1559347200, 1561939200, 1564617600, 1567296000, 1569888000, 1572566400,
1575158400, 1577836800, 1580515200, 1583020800, 1585699200, 1588291200,
1590969600, 1593561600, 1596240000, 1598918400, 1601510400, 1604188800,
1606780800, 1609459200, 1612137600, 1614556800, 1617235200, 1619827200,
1622505600, 1625097600, 1627776000, 1630454400, 1633046400, 1635724800,
1638316800, 1640995200, 1643673600, 1646092800, 1648771200, 1651363200,
1420070400, 1422748800, 1425168000, 1427846400, 1430438400, 1433116800,
1435708800, 1438387200, 1441065600, 1443657600, 1446336000, 1448928000,
1451606400, 1454284800, 1456790400, 1459468800, 1462060800, 1464739200,
1467331200, 1470009600, 1472688000, 1475280000, 1477958400, 1480550400,
1483228800, 1485907200, 1488326400, 1491004800, 1493596800, 1496275200,
1498867200, 1501545600, 1504224000, 1506816000, 1509494400, 1512086400,
1514764800, 1517443200, 1519862400, 1522540800, 1525132800, 1527811200,
1530403200, 1533081600, 1535760000, 1538352000, 1541030400, 1543622400,
1546300800, 1548979200, 1551398400, 1554076800, 1556668800, 1559347200,
1561939200, 1564617600, 1567296000, 1569888000, 1572566400, 1575158400,
1577836800, 1580515200, 1583020800, 1585699200, 1588291200, 1590969600,
1593561600, 1596240000, 1598918400, 1601510400, 1604188800, 1606780800,
1609459200, 1612137600, 1614556800, 1617235200, 1619827200, 1622505600,
1625097600, 1627776000, 1630454400, 1633046400, 1635724800, 1638316800,
1640995200, 1643673600, 1646092800, 1648771200, 1651363200, 1525132800,
1527811200, 1530403200, 1533081600, 1535760000, 1538352000, 1541030400,
1543622400, 1546300800, 1548979200, 1551398400, 1554076800, 1556668800,
1559347200, 1561939200, 1564617600, 1567296000, 1569888000, 1572566400,
1575158400, 1577836800, 1580515200, 1583020800, 1585699200, 1588291200,
1590969600, 1593561600, 1596240000, 1598918400, 1601510400, 1604188800,
1606780800, 1609459200, 1612137600, 1614556800, 1617235200, 1619827200,
1622505600, 1625097600, 1627776000, 1630454400, 1633046400, 1635724800,
1638316800, 1640995200, 1643673600, 1646092800, 1648771200, 1651363200
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), value = c(2083932,
1950171, 1980926, 2461828, 2100801, 1933544, 2233212, 2281489,
2332978, 2435590, 2324081, 2203801, 2086510, 1956418, 1905085,
1701513, 1701002, 6972.461, 6225.307, 6277.703, 6806.333, 457963.4,
9247.682, 32677.13, 12119.93, 24109.31, 178369.4, 46707.13, 116648,
8813.909, 12592.63, 23458.46, 17243.99, 41718.48, 138753.3, 147283.9,
159596.9, 162527.9, 172139, 186912.8, 199447.8, 211219.8, 220876.7,
229026.5, 240222.2, 258874.8, 269721.6, 281965.2, 301389.2, 315747.9,
339189.8, 181553, 183511, 178432, 170117, 174254, 157093, 155940,
148820, 138293, 140852, 136471, 148723, 125715, 124786, 120678,
117131, 121437, 117071, 119393, 110149, 102997, 105716, 100807,
113581, 123014, 125888, 120772, 122770, 117110, 118830, 127888,
126463, 128019, 131106, 132461, 138721, 152699, 137878, 149970,
143298, 147116, 145526, 145869, 147309, 148051, 153455, 147045,
163636, 151536, 143592, 142710, 144018, 169477, 191491, 193601,
182294, 183088, 181907, 165129, 196131, 189404, 181571, 180107,
183752, 190208, 189822, 184403, 186700, 143214, 229631, 204574,
208789, 204674.7, 198314.6, 190151.9, 192424.7, 401053.8, 389546.8,
378793.3, 58621.6, 56900.61, 58544.35, 53683.21, 54619.97, 52336.17,
52125.07, 49019.01, 50733.09, 48224.08, 114230, 73488.5, 78062,
66257.18, 63709.47, -63834.9, -69282.6, -34674.5, -21494.4, 158682.7,
85341.02, 18014.91, 11915.6, 13481.26, 30411.9, 15942.67, 18123.67,
67, 4707, 3830, 2662, 4826, 7721, 8574, 6105, 9574, 15969, 24515,
23750, 24859, 29581, 36583, 37539, 35040, 38145, 33826, 39403,
43919, 48045, 52710, 49241, 50587, 51965, 62260, 58783, 58935,
51637, 42407, 50253, 45102, 49212, 46878, 48166, 50818, 51589,
57052, 68370.13, 83220.78, 71789.06, 84793.53, 83499.91, 92959.89,
110604.4, 113749.3, 116861.6, 118703.6, 114356.9, 133689.8, 107931.9,
134176.7, 119300.7, 118410.6, 121198.6, 7, 2, 209, 738, 1500,
2598, 2836, 4013, 4547, 6752, 9808, 13200, 16434, 21976, 32610,
42498, 54298, 57261, 63159, 65965, 68626, 71571, 69324, 70684,
68006, 69319, 70595, 70615, 73321, 65882.01, 70125.35, 73302.44,
72151.86, 74019.36, 73480.6, 77689.52, 73955.09, 71458.99, 79560.74,
77714.22, 87302.14, 388843, 151880.8, 199528.4, 158357.5, 179707.5,
5855, 3734, 3016, 20000, 93, 51228, 152593, 147707.3, 152342.3,
170402.7, 195926.9, 169838.8, 185421.8, 208586.4, 232198.2, 235424,
278144.2, 239536.8, 274178, 229447.4, 201875.7, 197140.7, 176340,
199179, 10629.22, 11069.22, 76920.18, 49681.47, 54629.24, 41784.58,
23420.33, 66861.4, 46128.38, 160298, 55595.37, 24998.86, 42793.85,
190414, 121946.5, 15236.71, 250271.1, 263481.5, 900230.2, 12519.21,
3846.68, 80.13, 99, 99, 99, 99, 5500, 60.75, 336.5468, 2658.514,
17473.36, 31903.92, 42934.65, 64549.45, 42786.9, 64528.09, 68950.21,
62334.35, 78381.29, 76575.28, 79843.12, 63637.71, 67945.82, 66400.98,
70852.86, 80654.77, 82728.91, 84920.54, 78872.71, 74230.72, 79718.15,
70278.81, 77311.33, 65477.07, 63883.88, 60920.48, 59463.09, 63588.72,
3, -14, 116, 32, 725, 7957, 5260, 7544, 7036, 9859, 11450, 12855,
15742, 14366, 17234, 17514, 16319, 19743, 19459, 21566, 23887,
24344, 26813, 25112, 32070, 33459, 25350, 32571, 30693, 33469,
31755, 32790, 33605, 28326, 34746, 55690, 23516, 25299, 28292,
25978, 22095, 26011, 26198, 26532, 37058, 39477, 39097, 40383,
43719, 43858.15, 44768.15, 47912.44, 58174.46, 58314.08, 56466.82,
58165.62, 50670.24, 45213.39, 51334.23, 45132.34, 51714.14, 39140.62,
35521.31, 35131.7, 32224.89, 32599.64, 1265237, 1233457, 1296608,
1297813, 1198245, 1213322, 1239841, 1223294, 1276484, 1354942,
1372216, 1487684, 1384082, 1427289, 1419981, 1558989, 1536445,
1537975, 1528473, 1547607, 1611710, 1485140, 1487032, 1484354,
1411420, 1430510, 1517915, 1499737, 1523590, 1511891, 1532000,
1587068, 1533391, 1541699, 1506859, 1552920, 1441443, 1422334,
1439888, 1438811, 1396145, 1395038, 1375798, 1362614, 1326090,
1329000, 1244732, 1354162, 1216691, 1173415, 1176548, 1141411,
1066206, 1019118, 988499, 1001852, 901223, 930559, 863214, 904869,
806624, 789492, 775546, 752936, 748191, 733050, 732415, 707040,
678413, 654274, 666637, 663248, 590168.2, 612531.1, 600121.2,
582241.1, 591551.2, 572399.3, 558498.5, 525632.6, 530394, 526828.8,
383121.9, 362122.4, 368189.3, 347611.9, 346074.6, 339376.3, 337119.3,
20000, 13630, 132508.9, 875124.9, 1336834, 1598590, 1656514,
1920719, 2433575, 1918492, 1399765, 1160387, 1018087, 1000060,
1000407, 844354.6, 868914.5, 755539.4, 793827.8, 108750, 97225,
95533, 65371, 64017, 63117, 76913, 78131, 70477, 79362, 75902,
89955, 93884, 91481, 97189, 92807, 33600, 85593, 96928, 94048,
90721, 91553, 83804, 185770, 106780, 98345, 106698, 92279, 84154,
84532, 91128, 90685, 95075, 84203, 81623, 91576, 86581, 80576,
87585, 74325, 67120, 77766, 83139, 76859, 74956, 70956, 66650,
94019, 77882, 66361, 68573, 57188, 53975, 57676, 53441, 53591,
53797, 57749, 51933, 76797, 38184, 34550, 38329, 25439, 25826,
40405, 76945, 26897, 17088, 34842, 25011, 27660, 33902.41, 45435.43,
43605.72, 51204.28, 50339.34, 54299.58, 58077.71, 55829.12, 46393.98,
55530.54, 53173.71, 39094.48, 62973.63, 52255.38, 48705.67, 34063.43,
41231.58, 80920, 75024, 69198, 69131, 76573, 76219, 91797, 103054,
110183, 123885, 123468, 134442, 139281, 147540, 155182, 187975,
172145, 204750, 233247, 236003, 286992, 279767, 287995, 335349,
307508, 344059, 341206, 366931, 374969, 415748, 443059, 462397,
498197, 481533, 499971, 520237, 458758, 448274, 491779, 406120,
437307, 469965, 409020, 425137, 474399, 362592, 406261, 411975,
328467, 319335, 395716, 242726, 311600, 385376, 219880, 238926,
135465, 180974, 194343, 170154, 174062, 254612, 102527, 163510,
242587, 96332, 160346, 165524, 170899, 255716, 98249, 171123,
265813.4, 176660.1, 76303.95, 156814.9, 160126.4, 161155.2, 229082.6,
90114.06, 147917.2, 210152.1, 100151.9, 142053, 143008.3, 114483.3,
125425.2, 126261.2, 118942, 5099, 5090, 5100, 3104, 3136, 3105,
3152, 3539, 3511, 3625, 5551, 6049, 5911, 6639, 7795, 10860,
12409, 14373, 18238, 19337, 24101, 23549, 26573, 47556, 36839,
32603, 40394, 38388, 40688, 41343, 49460, 48082, 50576, 65597,
57927, 60619, 57896, 57731, 49487, 57172, 64667, 59878, 58185,
58663, 59077, 57329, 57258, 53836, 45980, 49201, 48898, 46642,
43119, 41641, 39429, 37460, 40300, 32335, 44302, 37277, 34744,
33753, 31581, 33095, 48197, 32721, 33106, 33773, 45147, 34405,
33266, 35361, 33138.96, 33652.35, 41994.9, 48588.7, 49100.3,
45410.89, 46317.88, 45240.67, 42217.39, 41093.69, 37168.68, 36655.65,
33175.78, 32024.01, 38002.98, 33357.68, 28974.01, 33, 11781,
50817, 82293, 118641, 112754, 112131, 133472, 131598, 129799,
172241, 115247, 127161, 129828, 133895, 140692, 138041, 138859,
134777, 160361, 139706, 142114, 121942, 107380, 126223, 96955,
92907, 82222, 87763, 95132, 99504, 122739, 144682.7, 144029.7,
127644.2, 117313.8, 118433.2, 126402.6, 147662.4, 152417.9, 154328,
219567.4, 88241.14, 167967.7, 215814.9, 202348.8, 250632.2, 261665.9,
270071.3), idn = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L)), row.names = c(75L,
76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L,
89L, 90L, 91L, 144L, 145L, 146L, 147L, 148L, 149L, 150L, 151L,
152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 188L, 189L,
190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L,
201L, 202L, 203L, 204L, 229L, 230L, 231L, 232L, 233L, 234L, 235L,
236L, 237L, 238L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L,
247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L,
258L, 259L, 260L, 261L, 262L, 263L, 264L, 265L, 266L, 267L, 268L,
269L, 270L, 271L, 272L, 273L, 274L, 275L, 276L, 277L, 278L, 279L,
280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L,
291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L, 299L, 300L, 301L,
302L, 303L, 304L, 305L, 306L, 307L, 308L, 309L, 310L, 311L, 312L,
313L, 314L, 315L, 316L, 317L, 326L, 327L, 328L, 329L, 330L, 331L,
332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L, 340L, 341L, 342L,
367L, 368L, 369L, 370L, 371L, 372L, 373L, 374L, 375L, 376L, 377L,
378L, 379L, 380L, 381L, 382L, 383L, 384L, 385L, 386L, 387L, 388L,
389L, 390L, 391L, 392L, 393L, 394L, 395L, 396L, 397L, 398L, 399L,
400L, 401L, 402L, 403L, 404L, 405L, 406L, 407L, 408L, 409L, 410L,
411L, 412L, 413L, 414L, 415L, 416L, 417L, 418L, 419L, 420L, 421L,
422L, 423L, 424L, 425L, 426L, 427L, 428L, 429L, 430L, 431L, 432L,
433L, 434L, 435L, 436L, 437L, 438L, 439L, 440L, 441L, 442L, 443L,
444L, 445L, 446L, 447L, 448L, 449L, 450L, 451L, 452L, 453L, 454L,
455L, 456L, 457L, 458L, 459L, 460L, 461L, 462L, 463L, 464L, 465L,
466L, 467L, 468L, 536L, 537L, 538L, 539L, 540L, 541L, 542L, 543L,
544L, 545L, 546L, 547L, 548L, 549L, 550L, 551L, 552L, 553L, 554L,
555L, 556L, 557L, 558L, 559L, 647L, 648L, 649L, 650L, 651L, 652L,
653L, 654L, 655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 663L,
665L, 666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 680L, 681L,
682L, 683L, 684L, 685L, 686L, 687L, 688L, 689L, 690L, 691L, 692L,
693L, 694L, 741L, 742L, 743L, 744L, 745L, 746L, 747L, 748L, 749L,
750L, 751L, 752L, 753L, 754L, 755L, 756L, 757L, 784L, 785L, 786L,
787L, 788L, 789L, 790L, 791L, 792L, 793L, 794L, 795L, 796L, 797L,
798L, 799L, 800L, 801L, 802L, 803L, 804L, 805L, 806L, 807L, 808L,
809L, 810L, 811L, 812L, 813L, 814L, 815L, 816L, 817L, 818L, 819L,
820L, 821L, 822L, 823L, 824L, 825L, 826L, 827L, 828L, 829L, 830L,
831L, 832L, 833L, 834L, 835L, 836L, 837L, 838L, 839L, 840L, 841L,
842L, 843L, 844L, 845L, 846L, 847L, 848L, 849L, 880L, 881L, 882L,
883L, 884L, 885L, 886L, 887L, 888L, 889L, 890L, 891L, 892L, 893L,
894L, 895L, 896L, 897L, 898L, 899L, 900L, 901L, 902L, 903L, 904L,
905L, 906L, 907L, 908L, 909L, 910L, 911L, 912L, 913L, 914L, 915L,
916L, 917L, 918L, 919L, 920L, 921L, 922L, 923L, 924L, 925L, 926L,
927L, 928L, 929L, 930L, 931L, 932L, 933L, 934L, 935L, 936L, 937L,
938L, 939L, 940L, 941L, 942L, 943L, 944L, 945L, 946L, 947L, 948L,
949L, 950L, 951L, 952L, 953L, 954L, 955L, 956L, 957L, 958L, 959L,
960L, 961L, 962L, 963L, 964L, 965L, 966L, 967L, 968L, 1052L,
1053L, 1054L, 1055L, 1056L, 1057L, 1058L, 1059L, 1060L, 1061L,
1062L, 1063L, 1064L, 1065L, 1066L, 1067L, 1068L, 1069L, 1070L,
1151L, 1152L, 1153L, 1154L, 1155L, 1156L, 1157L, 1158L, 1159L,
1160L, 1161L, 1162L, 1163L, 1164L, 1165L, 1166L, 1167L, 1168L,
1169L, 1170L, 1171L, 1172L, 1173L, 1174L, 1175L, 1176L, 1177L,
1178L, 1179L, 1180L, 1181L, 1182L, 1183L, 1184L, 1185L, 1186L,
1187L, 1188L, 1189L, 1190L, 1191L, 1192L, 1193L, 1194L, 1195L,
1196L, 1197L, 1198L, 1199L, 1200L, 1201L, 1202L, 1203L, 1204L,
1205L, 1206L, 1207L, 1208L, 1209L, 1210L, 1211L, 1212L, 1213L,
1214L, 1215L, 1216L, 1217L, 1218L, 1219L, 1220L, 1221L, 1222L,
1223L, 1224L, 1225L, 1226L, 1227L, 1228L, 1229L, 1230L, 1231L,
1232L, 1233L, 1234L, 1235L, 1236L, 1237L, 1238L, 1239L, 1586L,
1587L, 1588L, 1589L, 1590L, 1591L, 1592L, 1593L, 1594L, 1595L,
1596L, 1597L, 1598L, 1599L, 1600L, 1601L, 1602L, 1603L, 1604L,
1605L, 1606L, 1607L, 1608L, 1609L, 1610L, 1611L, 1612L, 1613L,
1614L, 1615L, 1616L, 1617L, 1618L, 1619L, 1620L, 1621L, 1622L,
1623L, 1624L, 1625L, 1626L, 1627L, 1628L, 1629L, 1630L, 1631L,
1632L, 1633L, 1634L, 1635L, 1636L, 1637L, 1638L, 1639L, 1640L,
1641L, 1642L, 1643L, 1644L, 1645L, 1646L, 1647L, 1648L, 1649L,
1650L, 1651L, 1652L, 1653L, 1654L, 1655L, 1656L, 1657L, 1658L,
1659L, 1660L, 1661L, 1662L, 1663L, 1664L, 1665L, 1666L, 1667L,
1668L, 1669L, 1670L, 1671L, 1672L, 1673L, 1674L, 1846L, 1847L,
1848L, 1849L, 1850L, 1851L, 1852L, 1853L, 1854L, 1855L, 1856L,
1857L, 1858L, 1859L, 1860L, 1861L, 1862L, 1863L, 1864L, 1865L,
1866L, 1867L, 1868L, 1869L, 1870L, 1871L, 1872L, 1873L, 1874L,
1875L, 1876L, 1877L, 1878L, 1879L, 1880L, 1881L, 1882L, 1883L,
1884L, 1885L, 1886L, 1887L, 1888L, 1889L, 1890L, 1891L, 1892L,
1893L, 1894L, 1895L, 1896L, 1897L, 1898L, 1899L, 1900L, 1901L,
1902L, 1903L, 1904L, 1905L, 1906L, 1907L, 1908L, 1909L, 1910L,
1911L, 1912L, 1913L, 1914L, 1915L, 1916L, 1917L, 1918L, 1919L,
1920L, 1921L, 1922L, 1923L, 1924L, 1925L, 1926L, 1927L, 1928L,
1929L, 1930L, 1931L, 1932L, 1933L, 1934L, 1993L, 1994L, 1995L,
1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L, 2004L,
2005L, 2006L, 2007L, 2008L, 2009L, 2010L, 2011L, 2012L, 2013L,
2014L, 2015L, 2016L, 2017L, 2018L, 2019L, 2020L, 2021L, 2022L,
2023L, 2024L, 2025L, 2026L, 2027L, 2028L, 2029L, 2030L, 2031L,
2032L, 2033L, 2034L, 2035L, 2036L, 2037L, 2038L, 2039L, 2040L,
2041L), class = "data.frame")

Related

Merging two files based on dates with missing values

I am trying to merge two files together based on dates:
However, there are two issues:
I cannot use the left join function due to one of the files having the dates set as characters, and the other one set as dates. Changing one of the files values to dates does not fix the issue as it creates a list instead
Using the merge function leads to a lot of missing values, as one of my dataset does not contain data for each date
jointdataset <- merge(group_df, group_tweet, by = 'date', all.x= TRUE)
View(jointdataset)
jointdataset <- dplyr::left_join(group_df, group_tweet)
Here is how my data looks like
> dput(group_tweet)
structure(list(date = structure(c(18628, 18629, 18630, 18631,
18632, 18633, 18634, 18635, 18636, 18637, 18638, 18639, 18640,
18641, 18642, 18643, 18644, 18645, 18646, 18647, 18648, 18649,
18650, 18651, 18652, 18653, 18654, 18655, 18656, 18657, 18658,
18659, 18660, 18661, 18662, 18663, 18664, 18665, 18666, 18667,
18668, 18669, 18670, 18671, 18672, 18673, 18674, 18675, 18676,
18677, 18678, 18679, 18680, 18681, 18682, 18683, 18684, 18685,
18686, 18687, 18688, 18689, 18690, 18691, 18692, 18693, 18694,
18695, 18696, 18697, 18698, 18699, 18700, 18701, 18702, 18703,
18704, 18705, 18706, 18707, 18708, 18709, 18710, 18711, 18712,
18713, 18714, 18715, 18716, 18717, 18718, 18719, 18720, 18721,
18722, 18723, 18724, 18725, 18726, 18727, 18728, 18729, 18730,
18731, 18732, 18733, 18734, 18735, 18736, 18737, 18738, 18739,
18740, 18741, 18742, 18743, 18744, 18745, 18746, 18747, 18748,
18749, 18750, 18751, 18752, 18753, 18754, 18755, 18756, 18757,
18758, 18759, 18760, 18761, 18762, 18763, 18764, 18765, 18766,
18767, 18768, 18769, 18770, 18771, 18772, 18773, 18774, 18775,
18776, 18777, 18778, 18779, 18780, 18781, 18782, 18783, 18784,
18785, 18786, 18787, 18788, 18789, 18790, 18791, 18792, 18793,
18794, 18795, 18796, 18797, 18798, 18799, 18800, 18801, 18802,
18803, 18804, 18805, 18806, 18807, 18808), class = "Date"), `length(text)` = c(1324L,
1548L, 1297L, 1585L, 1636L, 1583L, 1492L, 1676L, 1745L, 1389L,
1718L, 1781L, 1858L, 1798L, 1714L, 1808L, 1315L, 1644L, 1603L,
1820L, 1770L, 1843L, 1885L, 1390L, 1763L, 1875L, 1912L, 1812L,
1764L, 2117L, 1641L, 1914L, 1963L, 2092L, 1968L, 2021L, 2023L,
1331L, 1557L, 1555L, 1904L, 2034L, 1850L, 2067L, 1507L, 1738L,
1915L, 2057L, 1931L, 1859L, 2010L, 1525L, 1835L, 1850L, 1958L,
1848L, 1929L, 2015L, 1449L, 1823L, 1796L, 1902L, 1888L, 1875L,
2078L, 1442L, 1757L, 1877L, 2104L, 1926L, 1949L, 2175L, 1604L,
2030L, 1918L, 2011L, 1978L, 1959L, 2171L, 1528L, 1936L, 1889L,
2132L, 1907L, 2173L, 2233L, 1581L, 1793L, 1986L, 2128L, 2030L,
1805L, 1954L, 1459L, 1691L, 1967L, 2049L, 1835L, 1948L, 2246L,
1581L, 1950L, 1904L, 2245L, 2053L, 1877L, 1913L, 1571L, 1932L,
2004L, 2058L, 2087L, 1989L, 2180L, 1567L, 1865L, 1995L, 2144L,
2169L, 2148L, 2318L, 1606L, 1856L, 1948L, 2036L, 1887L, 2021L,
2132L, 1390L, 1717L, 1872L, 1919L, 1867L, 1994L, 2083L, 1509L,
1786L, 1808L, 1860L, 1854L, 1813L, 2102L, 1513L, 1890L, 1877L,
2063L, 1857L, 1827L, 2059L, 1413L, 1614L, 2153L, 1859L, 1920L,
1877L, 2106L, 1458L, 1822L, 1851L, 2005L, 1984L, 2097L, 2396L,
1607L, 2106L, 2256L, 2398L, 2245L, 2239L, 2287L, 1564L, 1880L,
1991L, 2053L, 2017L, 2012L, 1998L, 1361L, 1663L, 1778L, 1987L
)), row.names = c(NA, -181L), class = c("tbl_df", "tbl", "data.frame"
))
dput(group_df)
structure(list(date = c("01/01/2021", "01/05/2021", "01/06/2021",
"01/07/2021", "01/11/2021", "01/12/2021", "01/14/2021", "01/15/2021",
"01/18/2021", "01/19/2021", "01/20/2021", "01/21/2021", "01/22/2021",
"01/23/2021", "01/26/2021", "01/27/2021", "01/28/2021", "01/29/2021",
"01/31/2021", "02/01/2021", "02/02/2021", "02/04/2021", "02/08/2021",
"02/09/2021", "02/10/2021", "02/11/2021", "02/12/2021", "02/15/2021",
"02/16/2021", "02/18/2021", "02/19/2021", "02/22/2021", "02/23/2021",
"02/24/2021", "02/25/2021", "02/27/2021", "03/01/2021", "03/02/2021",
"03/04/2021", "03/05/2021", "03/06/2021", "03/07/2021", "03/08/2021",
"03/09/2021", "03/11/2021", "03/14/2021", "03/15/2021", "03/16/2021",
"03/17/2021", "03/18/2021", "03/19/2021", "03/20/2021", "03/21/2021",
"03/22/2021", "03/23/2021", "03/24/2021", "03/25/2021", "03/26/2021",
"03/28/2021", "03/29/2021", "03/30/2021", "03/31/2021", "04/01/2021",
"04/02/2021", "04/03/2021", "04/04/2021", "04/05/2021", "04/06/2021",
"04/07/2021", "04/08/2021", "04/09/2021", "04/10/2021", "04/11/2021",
"04/12/2021", "04/13/2021", "04/14/2021", "04/15/2021", "04/16/2021",
"04/17/2021", "04/18/2021", "04/19/2021", "04/20/2021", "04/21/2021",
"04/22/2021", "04/23/2021", "04/24/2021", "04/26/2021", "04/27/2021",
"04/28/2021", "04/29/2021", "04/30/2021", "05/01/2021", "05/02/2021",
"05/03/2021", "05/04/2021", "05/05/2021", "05/06/2021", "05/07/2021",
"05/08/2021", "05/10/2021", "05/11/2021", "05/12/2021", "05/13/2021",
"05/14/2021", "05/15/2021", "05/18/2021", "05/19/2021", "05/20/2021",
"05/21/2021", "05/22/2021", "05/23/2021", "05/25/2021", "05/26/2021",
"05/27/2021", "05/29/2021", "05/31/2021", "06/01/2021", "06/02/2021",
"06/03/2021", "06/04/2021", "06/05/2021", "06/06/2021", "06/07/2021",
"06/08/2021", "06/09/2021", "06/10/2021", "06/11/2021", "06/12/2021",
"06/13/2021", "06/14/2021", "06/15/2021", "06/16/2021", "06/17/2021"
), `length(category)` = c(4L, 8L, 4L, 4L, 4L, 12L, 8L, 8L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 8L, 9L, 25L, 10L, 5L, 10L,
5L, 20L, 5L, 5L, 19L, 10L, 20L, 5L, 5L, 5L, 2L, 12L, 22L, 14L,
2L, 4L, 6L, 9L, 5L, 37L, 5L, 4L, 10L, 12L, 21L, 4L, 4L, 6L, 6L,
9L, 16L, 9L, 6L, 13L, 2L, 19L, 24L, 20L, 8L, 25L, 16L, 5L, 24L,
27L, 24L, 6L, 9L, 15L, 8L, 25L, 35L, 26L, 8L, 2L, 5L, 14L, 12L,
20L, 19L, 7L, 9L, 5L, 4L, 17L, 13L, 15L, 8L, 10L, 7L, 5L, 16L,
11L, 16L, 10L, 6L, 3L, 22L, 10L, 10L, 3L, 1L, 7L, 4L, 6L, 4L,
5L, 3L, 6L, 3L, 3L, 1L, 3L, 9L, 6L, 4L, 2L, 1L, 1L, 3L, 5L, 2L,
4L, 2L, 2L, 1L, 5L, 5L, 6L, 3L), `sum(usd_pledged)` = c(50278.64,
366279.590415302, 172073.0471292, 230.537553792, 304353.5676352,
285277.861423738, 931521.92, 62322.104033708, 292739.37663744,
97895.025306156, 20538.4758468, 5716, 69712, 15248.7519561728,
1257502.99126928, 102268, 32151.762183708, 70322.17520884, 27549.00453216,
8371657.96195552, 1420782.4068818, 137818.171860595, 1175436.75496273,
1770825.83285245, 1070, 178761.8127624, 10016.918409372, 146129.2,
610608.234267955, 676175.367448825, 1274147.86429578, 45595.6660422,
1776940, 4198.748196, 17.02446963, 55272.18380506, 490750.12364435,
571800.5, 227.26420984, 619.23335154, 5942.151506976, 1098.48977709,
87300, 1879564.14902818, 57100, 3.628861728, 715993, 228885.860968739,
1005412.33040269, 32978.39955816, 1956.52590528, 5789.84841572,
508.6539266268, 192238.643979976, 278988.70418106, 32470.60072344,
10653.5543364, 333900.00289616, 2467.35065664, 698082.326436438,
581461.49769354, 170032.27513805, 24516.65281874, 11530.3738156855,
20060.6125168384, 154030.2061095, 215919.1704622, 1320696.42919177,
2000470.11990896, 1414.108082664, 12429.5108974052, 80676.567104964,
3211.42501648, 69994.39317561, 827188.797715076, 51349.427891072,
47925.216359587, 42, 28391.25545206, 6199141.75469484, 16078.9170341546,
724307.969231123, 238317.166592813, 243887.2812338, 3856.910710253,
5982.1359855268, 1986.4520326, 180186.734055936, 25818.301703542,
284175.24917946, 27486.5134227176, 51837.3569258, 218101.634171675,
543.2343820104, 299634.97422679, 9200.1639420603, 112660.244016819,
27675.2965010449, 5203.03118806, 75650.25, 327968.549088524,
1002.27102748, 37881.2795828444, 2896.1824198269, 596, 206880.064933601,
1688.14367074, 19176.1722666628, 48811.21823157, 4572.83962465,
375.36475346, 126743.686979946, 489.0998, 4042.91231235, 1343.0098244,
2286.711086, 77485.7681307, 25272.4433349128, 11630.0007860946,
377.22065991, 199.9004139, 161, 2667.93172391, 69404.71338983,
23796.67811208, 17174.64072667, 9950.0416377665, 35443.95356773,
184.603426004, 85934.0997877056, 5603.88739935, 2306.02823117,
13.0064795336), `sum(backers_count)` = c(2880L, 6588L, 3528L,
16L, 4204L, 6632L, 15404L, 1672L, 3588L, 416L, 464L, 364L, 1488L,
228L, 17124L, 2284L, 1348L, 2324L, 744L, 185822L, 35095L, 5980L,
24615L, 32525L, 40L, 4650L, 450L, 2640L, 15952L, 9275L, 16404L,
990L, 35075L, 79L, 6L, 1578L, 10705L, 9302L, 12L, 20L, 36L, 91L,
1505L, 40509L, 1890L, 4L, 9684L, 4196L, 16477L, 754L, 62L, 54L,
36L, 3787L, 3809L, 996L, 132L, 13216L, 50L, 12073L, 13826L, 4353L,
220L, 393L, 628L, 3607L, 6712L, 22403L, 30468L, 106L, 136L, 1854L,
102L, 1623L, 14638L, 1396L, 1923L, 6L, 426L, 161556L, 1020L,
6922L, 3575L, 1627L, 84L, 101L, 56L, 2291L, 450L, 2439L, 678L,
864L, 3195L, 17L, 6072L, 215L, 3119L, 1473L, 85L, 2306L, 7622L,
41L, 973L, 117L, 20L, 3127L, 45L, 424L, 819L, 84L, 12L, 3239L,
18L, 66L, 7L, 35L, 1651L, 651L, 242L, 25L, 13L, 6L, 59L, 1747L,
325L, 244L, 231L, 862L, 6L, 1819L, 74L, 66L, 4L)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -133L))
dput(group_df)
structure(list(date = c("01/01/2021", "01/05/2021", "01/06/2021",
"01/07/2021", "01/11/2021", "01/12/2021", "01/14/2021", "01/15/2021",
"01/18/2021", "01/19/2021", "01/20/2021", "01/21/2021", "01/22/2021",
"01/23/2021", "01/26/2021", "01/27/2021", "01/28/2021", "01/29/2021",
"01/31/2021", "02/01/2021", "02/02/2021", "02/04/2021", "02/08/2021",
"02/09/2021", "02/10/2021", "02/11/2021", "02/12/2021", "02/15/2021",
"02/16/2021", "02/18/2021", "02/19/2021", "02/22/2021", "02/23/2021",
"02/24/2021", "02/25/2021", "02/27/2021", "03/01/2021", "03/02/2021",
"03/04/2021", "03/05/2021", "03/06/2021", "03/07/2021", "03/08/2021",
"03/09/2021", "03/11/2021", "03/14/2021", "03/15/2021", "03/16/2021",
"03/17/2021", "03/18/2021", "03/19/2021", "03/20/2021", "03/21/2021",
"03/22/2021", "03/23/2021", "03/24/2021", "03/25/2021", "03/26/2021",
"03/28/2021", "03/29/2021", "03/30/2021", "03/31/2021", "04/01/2021",
"04/02/2021", "04/03/2021", "04/04/2021", "04/05/2021", "04/06/2021",
"04/07/2021", "04/08/2021", "04/09/2021", "04/10/2021", "04/11/2021",
"04/12/2021", "04/13/2021", "04/14/2021", "04/15/2021", "04/16/2021",
"04/17/2021", "04/18/2021", "04/19/2021", "04/20/2021", "04/21/2021",
"04/22/2021", "04/23/2021", "04/24/2021", "04/26/2021", "04/27/2021",
"04/28/2021", "04/29/2021", "04/30/2021", "05/01/2021", "05/02/2021",
"05/03/2021", "05/04/2021", "05/05/2021", "05/06/2021", "05/07/2021",
"05/08/2021", "05/10/2021", "05/11/2021", "05/12/2021", "05/13/2021",
"05/14/2021", "05/15/2021", "05/18/2021", "05/19/2021", "05/20/2021",
"05/21/2021", "05/22/2021", "05/23/2021", "05/25/2021", "05/26/2021",
"05/27/2021", "05/29/2021", "05/31/2021", "06/01/2021", "06/02/2021",
"06/03/2021", "06/04/2021", "06/05/2021", "06/06/2021", "06/07/2021",
"06/08/2021", "06/09/2021", "06/10/2021", "06/11/2021", "06/12/2021",
"06/13/2021", "06/14/2021", "06/15/2021", "06/16/2021", "06/17/2021"
), `length(category)` = c(4L, 8L, 4L, 4L, 4L, 12L, 8L, 8L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 8L, 9L, 25L, 10L, 5L, 10L,
5L, 20L, 5L, 5L, 19L, 10L, 20L, 5L, 5L, 5L, 2L, 12L, 22L, 14L,
2L, 4L, 6L, 9L, 5L, 37L, 5L, 4L, 10L, 12L, 21L, 4L, 4L, 6L, 6L,
9L, 16L, 9L, 6L, 13L, 2L, 19L, 24L, 20L, 8L, 25L, 16L, 5L, 24L,
27L, 24L, 6L, 9L, 15L, 8L, 25L, 35L, 26L, 8L, 2L, 5L, 14L, 12L,
20L, 19L, 7L, 9L, 5L, 4L, 17L, 13L, 15L, 8L, 10L, 7L, 5L, 16L,
11L, 16L, 10L, 6L, 3L, 22L, 10L, 10L, 3L, 1L, 7L, 4L, 6L, 4L,
5L, 3L, 6L, 3L, 3L, 1L, 3L, 9L, 6L, 4L, 2L, 1L, 1L, 3L, 5L, 2L,
4L, 2L, 2L, 1L, 5L, 5L, 6L, 3L), `sum(usd_pledged)` = c(50278.64,
366279.590415302, 172073.0471292, 230.537553792, 304353.5676352,
285277.861423738, 931521.92, 62322.104033708, 292739.37663744,
97895.025306156, 20538.4758468, 5716, 69712, 15248.7519561728,
1257502.99126928, 102268, 32151.762183708, 70322.17520884, 27549.00453216,
8371657.96195552, 1420782.4068818, 137818.171860595, 1175436.75496273,
1770825.83285245, 1070, 178761.8127624, 10016.918409372, 146129.2,
610608.234267955, 676175.367448825, 1274147.86429578, 45595.6660422,
1776940, 4198.748196, 17.02446963, 55272.18380506, 490750.12364435,
571800.5, 227.26420984, 619.23335154, 5942.151506976, 1098.48977709,
87300, 1879564.14902818, 57100, 3.628861728, 715993, 228885.860968739,
1005412.33040269, 32978.39955816, 1956.52590528, 5789.84841572,
508.6539266268, 192238.643979976, 278988.70418106, 32470.60072344,
10653.5543364, 333900.00289616, 2467.35065664, 698082.326436438,
581461.49769354, 170032.27513805, 24516.65281874, 11530.3738156855,
20060.6125168384, 154030.2061095, 215919.1704622, 1320696.42919177,
2000470.11990896, 1414.108082664, 12429.5108974052, 80676.567104964,
3211.42501648, 69994.39317561, 827188.797715076, 51349.427891072,
47925.216359587, 42, 28391.25545206, 6199141.75469484, 16078.9170341546,
724307.969231123, 238317.166592813, 243887.2812338, 3856.910710253,
5982.1359855268, 1986.4520326, 180186.734055936, 25818.301703542,
284175.24917946, 27486.5134227176, 51837.3569258, 218101.634171675,
543.2343820104, 299634.97422679, 9200.1639420603, 112660.244016819,
27675.2965010449, 5203.03118806, 75650.25, 327968.549088524,
1002.27102748, 37881.2795828444, 2896.1824198269, 596, 206880.064933601,
1688.14367074, 19176.1722666628, 48811.21823157, 4572.83962465,
375.36475346, 126743.686979946, 489.0998, 4042.91231235, 1343.0098244,
2286.711086, 77485.7681307, 25272.4433349128, 11630.0007860946,
377.22065991, 199.9004139, 161, 2667.93172391, 69404.71338983,
23796.67811208, 17174.64072667, 9950.0416377665, 35443.95356773,
184.603426004, 85934.0997877056, 5603.88739935, 2306.02823117,
13.0064795336), `sum(backers_count)` = c(2880L, 6588L, 3528L,
16L, 4204L, 6632L, 15404L, 1672L, 3588L, 416L, 464L, 364L, 1488L,
228L, 17124L, 2284L, 1348L, 2324L, 744L, 185822L, 35095L, 5980L,
24615L, 32525L, 40L, 4650L, 450L, 2640L, 15952L, 9275L, 16404L,
990L, 35075L, 79L, 6L, 1578L, 10705L, 9302L, 12L, 20L, 36L, 91L,
1505L, 40509L, 1890L, 4L, 9684L, 4196L, 16477L, 754L, 62L, 54L,
36L, 3787L, 3809L, 996L, 132L, 13216L, 50L, 12073L, 13826L, 4353L,
220L, 393L, 628L, 3607L, 6712L, 22403L, 30468L, 106L, 136L, 1854L,
102L, 1623L, 14638L, 1396L, 1923L, 6L, 426L, 161556L, 1020L,
6922L, 3575L, 1627L, 84L, 101L, 56L, 2291L, 450L, 2439L, 678L,
864L, 3195L, 17L, 6072L, 215L, 3119L, 1473L, 85L, 2306L, 7622L,
41L, 973L, 117L, 20L, 3127L, 45L, 424L, 819L, 84L, 12L, 3239L,
18L, 66L, 7L, 35L, 1651L, 651L, 242L, 25L, 13L, 6L, 59L, 1747L,
325L, 244L, 231L, 862L, 6L, 1819L, 74L, 66L, 4L)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -133L))
My final objective is to get a dataset, where i can get for each date the data, including for the days where there is missing data in one of the data sets
I assume your key problem is changing eg 01/15/2022 to a date. You can easily use the package lubridates mdy() function for this (install.packages('lubridate').
*adjusted from your comment.
You can run:
library(dplyr)
library(lubridate)
group_df %>%
mutate(date = mdy(date)) %>%
full_join(
group_tweet
) %>%
arrange(date)
Output is:
Joining, by = "date"
# A tibble: 181 × 5
date `length(category)` `sum(usd_pledged)` `sum(backers_count)` `length(text)`
<date> <int> <dbl> <int> <int>
1 2021-01-01 4 50279. 2880 1324
2 2021-01-02 NA NA NA 1548
3 2021-01-03 NA NA NA 1297
4 2021-01-04 NA NA NA 1585
5 2021-01-05 8 366280. 6588 1636
6 2021-01-06 4 172073. 3528 1583
7 2021-01-07 4 231. 16 1492
8 2021-01-08 NA NA NA 1676
9 2021-01-09 NA NA NA 1745
10 2021-01-10 NA NA NA 1389
# … with 171 more rows

How to use a loop to work out a model through several variables in R

Here my data for boosting
new=structure(list(B1 = c(6914L, 6914L, 6914L, 6958L, 6958L, 6958L,
6958L, 6914L, 6914L, 6914L, 6914L, 5672L, 6014L, 6014L, 6014L,
6014L, 6014L, 6958L, 6958L, 6958L, 6958L, 6958L, 6958L, 6914L,
6914L, 6914L, 6914L, 6092L, 6092L, 6092L, 6092L, 6092L, 6239L,
6239L, 6239L, 6239L, 6239L, 6239L, 6615L, 6615L, 6615L, 6615L,
6615L, 7038L, 7038L, 7038L, 7038L, 7038L, 7038L, 6602L, 8136L,
8136L, 7369L, 8136L, 8136L, 7369L, 8136L, 8136L, 8136L, 7369L,
7369L, 8136L, 8136L, 8136L, 8136L, 7369L, 7369L, 8136L, 8136L,
8136L, 8136L, 8317L, 8317L, 8317L, 8821L, 8821L, 8821L, 8821L,
8821L, 8317L, 8317L, 8821L, 8821L, 8821L, 8821L, 8821L, 8821L,
8317L, 8821L, 8821L, 8821L, 8821L, 8821L, 8821L, 8821L, 8821L,
8821L, 8821L, 8821L, 9245L), B2 = c(5560L, 5380L, 5644L, 5088L,
5280L, 5200L, 5472L, 5568L, 5560L, 5424L, 5404L, 4784L, 4696L,
4820L, 4588L, 4544L, 4452L, 4716L, 5048L, 5236L, 5416L, 5584L,
5824L, 5800L, 5932L, 5980L, 6112L, 4796L, 4860L, 5396L, 5900L,
5968L, 5968L, 5776L, 5440L, 5248L, 4884L, 4760L, 4796L, 4860L,
4776L, 4664L, 4716L, 4952L, 5168L, 5316L, 5548L, 5768L, 5900L,
5948L, 5796L, 5756L, 5912L, 5956L, 6000L, 6196L, 6044L, 6164L,
6268L, 6588L, 6508L, 6460L, 6608L, 6592L, 6600L, 7100L, 7016L,
6988L, 6952L, 6800L, 6644L, 7308L, 7340L, 7528L, 7492L, 7304L,
6928L, 6748L, 6764L, 7492L, 7648L, 7580L, 7416L, 7108L, 6864L,
7056L, 7164L, 7744L, 7720L, 7360L, 7188L, 7204L, 7280L, 7236L,
7520L, 7352L, 7352L, 7376L, 7320L, 7428L), B3 = c(4768L, 4840L,
4936L, 4320L, 4388L, 4572L, 4640L, 4704L, 4696L, 4488L, 4396L,
4002L, 4030L, 3960L, 3684L, 3680L, 3896L, 4212L, 4364L, 4508L,
4732L, 4896L, 4848L, 4872L, 4960L, 5052L, 4848L, 4308L, 4800L,
5216L, 5224L, 5248L, 5136L, 4720L, 4428L, 4120L, 3918L, 4052L,
4058L, 3806L, 3802L, 3930L, 4092L, 4324L, 4476L, 4604L, 4768L,
4980L, 5080L, 5288L, 4840L, 4936L, 5096L, 5040L, 5096L, 5292L,
5280L, 5360L, 5480L, 5584L, 5528L, 5524L, 5700L, 5736L, 5732L,
6136L, 5980L, 5884L, 5904L, 5820L, 5864L, 6488L, 6572L, 6476L,
6256L, 6024L, 5844L, 5884L, 6100L, 6684L, 6596L, 6376L, 6188L,
5952L, 6044L, 6212L, 6268L, 6668L, 6484L, 6336L, 6164L, 6332L,
6432L, 6396L, 6592L, 6548L, 6500L, 6464L, 6460L, 7008L), B4 = c(4960L,
4964L, 4540L, 4164L, 4412L, 4608L, 4628L, 4588L, 4416L, 4312L,
4372L, 3806L, 3652L, 3570L, 3480L, 3708L, 3886L, 4188L, 4284L,
4344L, 4704L, 4776L, 4772L, 4980L, 5000L, 4852L, 4508L, 4916L,
5356L, 5400L, 5268L, 5156L, 4620L, 4324L, 4016L, 3884L, 3854L,
3854L, 3770L, 3562L, 3708L, 3854L, 4084L, 4228L, 4440L, 4532L,
4784L, 5008L, 5292L, 5464L, 4868L, 4996L, 4908L, 4932L, 5060L,
5136L, 5280L, 5444L, 5492L, 5500L, 5560L, 5604L, 5704L, 5660L,
5716L, 5892L, 5844L, 5796L, 5752L, 5816L, 5892L, 6500L, 6488L,
6212L, 5928L, 5796L, 5876L, 6084L, 6284L, 6660L, 6424L, 6088L,
6004L, 6044L, 6268L, 6336L, 6664L, 6500L, 6308L, 6152L, 6288L,
6424L, 6376L, 6860L, 6464L, 6500L, 6508L, 6468L, 7144L, 7652L
), B5 = c(5554L, 5554L, 4782L, 4736L, 4736L, 5018L, 5018L, 4968L,
4968L, 4677L, 4677L, 3814L, 3667L, 3667L, 3594L, 3975L, 3975L,
4348L, 4348L, 4736L, 4736L, 5018L, 5018L, 4968L, 4968L, 4677L,
4677L, 4930L, 5524L, 5524L, 5229L, 5229L, 4424L, 4424L, 4113L,
4113L, 4069L, 4069L, 3857L, 3932L, 3932L, 4228L, 4228L, 4591L,
4591L, 4918L, 4918L, 5324L, 5324L, 5543L, 5327L, 5327L, 5301L,
5471L, 5471L, 5301L, 5471L, 5471L, 5846L, 5977L, 5977L, 5899L,
5899L, 6099L, 6099L, 5977L, 5977L, 5899L, 5899L, 6099L, 6099L,
6857L, 6517L, 6517L, 6220L, 6220L, 6418L, 6418L, 6969L, 6517L,
6517L, 6220L, 6220L, 6418L, 6418L, 6969L, 6969L, 6861L, 6581L,
6581L, 6729L, 6729L, 7265L, 7265L, 6581L, 6729L, 6729L, 7265L,
7265L, 8025L), B6 = c(5249L, 5249L, 4428L, 4553L, 4553L, 4832L,
4832L, 4741L, 4741L, 4428L, 4428L, 3736L, 3464L, 3464L, 3509L,
3894L, 3894L, 4270L, 4270L, 4553L, 4553L, 4832L, 4832L, 4741L,
4741L, 4428L, 4428L, 5030L, 5441L, 5441L, 4926L, 4926L, 4146L,
4146L, 3907L, 3907L, 3910L, 3910L, 3721L, 3831L, 3831L, 4201L,
4201L, 4509L, 4509L, 4871L, 4871L, 5235L, 5235L, 5217L, 5207L,
5207L, 5087L, 5290L, 5290L, 5087L, 5290L, 5290L, 5777L, 5721L,
5721L, 5746L, 5746L, 5982L, 5982L, 5721L, 5721L, 5746L, 5746L,
5982L, 5982L, 6504L, 6116L, 6116L, 5946L, 5946L, 6257L, 6257L,
6916L, 6116L, 6116L, 5946L, 5946L, 6257L, 6257L, 6916L, 6916L,
6407L, 6293L, 6293L, 6545L, 6545L, 7197L, 7197L, 6293L, 6545L,
6545L, 7197L, 7197L, 7998L), B7 = c(4893L, 4893L, 4138L, 4527L,
4527L, 4681L, 4681L, 4505L, 4505L, 4170L, 4170L, 3629L, 3388L,
3388L, 3545L, 3982L, 3982L, 4288L, 4288L, 4527L, 4527L, 4681L,
4681L, 4505L, 4505L, 4170L, 4170L, 5127L, 5268L, 5268L, 4703L,
4703L, 3996L, 3996L, 3775L, 3775L, 3713L, 3713L, 3594L, 3813L,
3813L, 4166L, 4166L, 4462L, 4462L, 4836L, 4836L, 5277L, 5277L,
4910L, 5235L, 5235L, 5001L, 5241L, 5241L, 5001L, 5241L, 5241L,
5688L, 5539L, 5539L, 5599L, 5599L, 5988L, 5988L, 5539L, 5539L,
5599L, 5599L, 5988L, 5988L, 6278L, 5864L, 5864L, 5931L, 5931L,
6177L, 6177L, 6896L, 5864L, 5864L, 5931L, 5931L, 6177L, 6177L,
6896L, 6896L, 6212L, 6159L, 6159L, 6382L, 6382L, 7383L, 7383L,
6159L, 6382L, 6382L, 7383L, 7383L, 7856L), B8 = c(4836L, 4840L,
5044L, 4074L, 4236L, 4404L, 4592L, 4668L, 4796L, 4628L, 4632L,
3914L, 3896L, 3796L, 3580L, 3598L, 3596L, 3830L, 4096L, 4320L,
4460L, 4648L, 4904L, 4980L, 4940L, 5148L, 5180L, 4164L, 4628L,
5304L, 5512L, 5592L, 5500L, 5216L, 4732L, 4380L, 4036L, 4008L,
3994L, 3784L, 3660L, 3650L, 3794L, 4018L, 4212L, 4296L, 4516L,
4648L, 4908L, 5148L, 4876L, 4828L, 4936L, 4992L, 5052L, 5236L,
5236L, 5336L, 5380L, 5708L, 5648L, 5624L, 5580L, 5724L, 5796L,
6280L, 6156L, 6012L, 5876L, 5864L, 5868L, 6488L, 6636L, 6752L,
6612L, 6268L, 5924L, 5968L, 6092L, 6752L, 6876L, 6764L, 6484L,
6176L, 6108L, 6300L, 6460L, 6924L, 6724L, 6528L, 6484L, 6352L,
6500L, 6600L, 6784L, 6876L, 6676L, 6616L, 6732L, 6896L), B8A = c(4679L,
4679L, 4098L, 4524L, 4524L, 4643L, 4643L, 4460L, 4460L, 3987L,
3987L, 3413L, 3294L, 3294L, 3490L, 3840L, 3840L, 4140L, 4140L,
4524L, 4524L, 4643L, 4643L, 4460L, 4460L, 3987L, 3987L, 5232L,
5152L, 5152L, 4421L, 4421L, 3863L, 3863L, 3697L, 3697L, 3561L,
3561L, 3558L, 3788L, 3788L, 4110L, 4110L, 4493L, 4493L, 4894L,
4894L, 5032L, 5032L, 4606L, 5209L, 5209L, 4889L, 5233L, 5233L,
4889L, 5233L, 5233L, 5787L, 5324L, 5324L, 5492L, 5492L, 6018L,
6018L, 5324L, 5324L, 5492L, 5492L, 6018L, 6018L, 5872L, 5544L,
5544L, 5876L, 5876L, 6279L, 6279L, 6963L, 5544L, 5544L, 5876L,
5876L, 6279L, 6279L, 6963L, 6963L, 6134L, 6187L, 6187L, 6547L,
6547L, 7280L, 7280L, 6187L, 6547L, 6547L, 7280L, 7280L, 7968L
), B9 = c(6752L, 6752L, 6752L, 7098L, 7098L, 7098L, 7098L, 6752L,
6752L, 6752L, 6752L, 4997L, 5626L, 5626L, 5626L, 5626L, 5626L,
7098L, 7098L, 7098L, 7098L, 7098L, 7098L, 6752L, 6752L, 6752L,
6752L, 5698L, 5698L, 5698L, 5698L, 5698L, 5408L, 5408L, 5408L,
5408L, 5408L, 5408L, 5685L, 5685L, 5685L, 5685L, 5685L, 6352L,
6352L, 6352L, 6352L, 6352L, 6352L, 5794L, 8407L, 8407L, 7048L,
8407L, 8407L, 7048L, 8407L, 8407L, 8407L, 7048L, 7048L, 8407L,
8407L, 8407L, 8407L, 7048L, 7048L, 8407L, 8407L, 8407L, 8407L,
8487L, 8487L, 8487L, 9610L, 9610L, 9610L, 9610L, 9610L, 8487L,
8487L, 9610L, 9610L, 9610L, 9610L, 9610L, 9610L, 8487L, 9610L,
9610L, 9610L, 9610L, 9610L, 9610L, 9610L, 9610L, 9610L, 9610L,
9610L, 10128L), B10 = c(4170L, 4170L, 3407L, 3301L, 3301L, 3612L,
3612L, 3600L, 3600L, 3352L, 3352L, 2502L, 2388L, 2388L, 2403L,
2659L, 2659L, 2979L, 2979L, 3301L, 3301L, 3612L, 3612L, 3600L,
3600L, 3352L, 3352L, 3856L, 4192L, 4192L, 3840L, 3840L, 3187L,
3187L, 2782L, 2782L, 2634L, 2634L, 2501L, 2562L, 2562L, 2792L,
2792L, 3068L, 3068L, 3405L, 3405L, 3816L, 3816L, 3858L, 3343L,
3343L, 3188L, 3438L, 3438L, 3188L, 3438L, 3438L, 3774L, 3543L,
3543L, 3653L, 3653L, 3934L, 3934L, 3543L, 3543L, 3653L, 3653L,
3934L, 3934L, 4224L, 3999L, 3999L, 3881L, 3881L, 4162L, 4162L,
4724L, 3999L, 3999L, 3881L, 3881L, 4162L, 4162L, 4724L, 4724L,
4293L, 4161L, 4161L, 4380L, 4380L, 5052L, 5052L, 4161L, 4380L,
4380L, 5052L, 5052L, 5756L), B11 = c(3124L, 3124L, 2514L, 2969L,
2969L, 3137L, 3137L, 2922L, 2922L, 2487L, 2487L, 1850L, 1822L,
1822L, 2014L, 2309L, 2309L, 2600L, 2600L, 2969L, 2969L, 3137L,
3137L, 2922L, 2922L, 2487L, 2487L, 3753L, 3535L, 3535L, 2823L,
2823L, 2296L, 2296L, 2151L, 2151L, 1974L, 1974L, 1924L, 2100L,
2100L, 2386L, 2386L, 2731L, 2731L, 3087L, 3087L, 3380L, 3380L,
3006L, 2740L, 2740L, 2443L, 2800L, 2800L, 2443L, 2800L, 2800L,
3228L, 2669L, 2669L, 2935L, 2935L, 3338L, 3338L, 2669L, 2669L,
2935L, 2935L, 3338L, 3338L, 3049L, 2893L, 2893L, 3087L, 3087L,
3550L, 3550L, 4235L, 2893L, 2893L, 3087L, 3087L, 3550L, 3550L,
4235L, 4235L, 3184L, 3242L, 3242L, 3774L, 3774L, 4487L, 4487L,
3242L, 3774L, 3774L, 4487L, 4487L, 5217L), B = c(20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L), E = c(20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L), C = c(20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L), OC = c(30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L
), OLS = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, -100L
))
Five column with depended vars (B,E, C ,OC ,OLS).
I must perform 5 boosting models. Simple i can do it.
Take this script, and just change target var 5 times(any dep var ~. )
# train GBM model
gbm.fit.final109 <- gbm(
formula = Value ~ .,
distribution = "gaussian",
data = new,
n.trees = 483,
interaction.depth = 5,
shrinkage = 0.1,
n.minobsinnode = 5,
bag.fraction = .65,
train.fraction = 1,
n.cores = NULL, # will use all cores by default
verbose = FALSE
)
However, is it possible to create some kind of loop that substitutes column with depended var from the list into the script? For example(mylistwithdepended_vars=c((B,E,C,OC,OLS)) ,
I.E.we take each dependent variable, as soon as it works out in a loop, we substitute another from the list, until through this loop we work out all the columns .
How can i do it.
As output i just want 5 models
gbm.fit.finalB
gbm.fit.finalE
gbm.fit.finalC
gbm.fit.finalOC
gbm.fit.finalOLS
Always appreciate your help, thanks.
Are you looking for something like the following?
library(gbm)
#> Loaded gbm 2.1.8
dependend <- c("B", "E", "C", "OC", "OLS")
mylistwithdepended_vars <- mget(dependend, envir = as.environment(new))
fun <- function(Value){
gbm.fit.final109 <- gbm(
formula = Value ~ .,
distribution = "gaussian",
data = new,
n.trees = 483,
interaction.depth = 5,
shrinkage = 0.1,
n.minobsinnode = 5,
bag.fraction = .65,
train.fraction = 1,
n.cores = NULL, # will use all cores by default
verbose = FALSE
)
}
gbm_models <- Map(fun, mylistwithdepended_vars)
old_par <- par(mfrow = c(1, 5))
mapply(summary, gbm_models, main = names(gbm_models))
#> B E C OC OLS
#> var character,17 character,17 character,17 character,17 character,17
#> rel.inf numeric,17 numeric,17 numeric,17 numeric,17 numeric,17
par(old_par)
Created on 2022-03-11 by the reprex package (v2.0.1)
The accepted solution fits a mysterious set of 5 models (and not the models the OP has in mind) because it's not clear what the predictors are in the formula Value ~ ..
It's better to be explicit what the models, the response and the predictors are.
library("gbm")
#> Loaded gbm 2.1.8
library("tidyverse")
data <- tibble(new)
# Let's define a function to fit a model ...
model_fn <- function(formula, data) {
# Generalized Boosted Regression
gbm(
formula = formula,
distribution = "gaussian",
data = data,
n.trees = 483,
interaction.depth = 5,
shrinkage = 0.1,
n.minobsinnode = 5,
bag.fraction = .65,
train.fraction = 1,
n.cores = NULL, # will use all cores by default
verbose = FALSE
)
}
# ... as well as a function to extract information from the fitted model.
summary_fn <- function(fit) {
# Generalized Boosted Regression
summary(fit, plotit = FALSE) %>%
as_tibble()
}
model_summaries <-
data %>%
pivot_longer(
# We want to fit 5 models, one for each of the following responses:
c(B, C, E, OC, OLS),
names_to = "response",
values_to = "y"
) %>%
nest_by(response) %>%
mutate(
fit = list(model_fn(
# For each response we want to use variables B1 through B11 as predictors.
y ~ B1 + B2 + B3 + B4 + B5 + B6 + B7 + B8 + B9 + B10 + B11,
data = data
))
) %>%
summarise(
summary_fn(fit)
)
#> `summarise()` has grouped output by 'response'. You can override using the
#> `.groups` argument.
model_summaries
#> # A tibble: 55 × 3
#> # Groups: response [5]
#> response var rel.inf
#> <chr> <chr> <dbl>
#> 1 B B1 1 e+ 2
#> 2 B B2 4.11e-29
#> 3 B B8 1.17e-29
#> 4 B B3 8.67e-30
#> 5 B B4 6.88e-30
#> 6 B B11 5.43e-30
#> 7 B B5 2.85e-30
#> 8 B B7 6.14e-31
#> 9 B B10 3.82e-31
#> 10 B B6 1.84e-31
#> # … with 45 more rows
PS. The gbm models fit your data very poorly. Are you sure that the response is Gaussian? It's easy to check that each response takes two unique values, and that each value is observed exactly 50 times.
data %>%
pivot_longer(
# We want to fit 5 models, one for each of the following responses:
c(B, C, E, OC, OLS),
names_to = "response",
values_to = "y"
) %>%
count(
response, y
)
#> # A tibble: 10 × 3
#> response y n
#> <chr> <int> <int>
#> 1 B 20 50
#> 2 B 50 50
#> 3 C 10 50
#> 4 C 20 50
#> 5 E 20 50
#> 6 E 30 50
#> 7 OC 10 50
#> 8 OC 30 50
#> 9 OLS 0 50
#> 10 OLS 10 50
Created on 2022-03-12 by the reprex package (v2.0.1)

How to calculate predicts and MAPE for a model with many dependent variables in R

This is dput() dataset from my previous question How to use a loop to work out a model through several variables in R, where Rui Barradas provided good solution.
new=structure(list(B1 = c(6914L, 6914L, 6914L, 6958L, 6958L, 6958L,
6958L, 6914L, 6914L, 6914L, 6914L, 5672L, 6014L, 6014L, 6014L,
6014L, 6014L, 6958L, 6958L, 6958L, 6958L, 6958L, 6958L, 6914L,
6914L, 6914L, 6914L, 6092L, 6092L, 6092L, 6092L, 6092L, 6239L,
6239L, 6239L, 6239L, 6239L, 6239L, 6615L, 6615L, 6615L, 6615L,
6615L, 7038L, 7038L, 7038L, 7038L, 7038L, 7038L, 6602L, 8136L,
8136L, 7369L, 8136L, 8136L, 7369L, 8136L, 8136L, 8136L, 7369L,
7369L, 8136L, 8136L, 8136L, 8136L, 7369L, 7369L, 8136L, 8136L,
8136L, 8136L, 8317L, 8317L, 8317L, 8821L, 8821L, 8821L, 8821L,
8821L, 8317L, 8317L, 8821L, 8821L, 8821L, 8821L, 8821L, 8821L,
8317L, 8821L, 8821L, 8821L, 8821L, 8821L, 8821L, 8821L, 8821L,
8821L, 8821L, 8821L, 9245L), B2 = c(5560L, 5380L, 5644L, 5088L,
5280L, 5200L, 5472L, 5568L, 5560L, 5424L, 5404L, 4784L, 4696L,
4820L, 4588L, 4544L, 4452L, 4716L, 5048L, 5236L, 5416L, 5584L,
5824L, 5800L, 5932L, 5980L, 6112L, 4796L, 4860L, 5396L, 5900L,
5968L, 5968L, 5776L, 5440L, 5248L, 4884L, 4760L, 4796L, 4860L,
4776L, 4664L, 4716L, 4952L, 5168L, 5316L, 5548L, 5768L, 5900L,
5948L, 5796L, 5756L, 5912L, 5956L, 6000L, 6196L, 6044L, 6164L,
6268L, 6588L, 6508L, 6460L, 6608L, 6592L, 6600L, 7100L, 7016L,
6988L, 6952L, 6800L, 6644L, 7308L, 7340L, 7528L, 7492L, 7304L,
6928L, 6748L, 6764L, 7492L, 7648L, 7580L, 7416L, 7108L, 6864L,
7056L, 7164L, 7744L, 7720L, 7360L, 7188L, 7204L, 7280L, 7236L,
7520L, 7352L, 7352L, 7376L, 7320L, 7428L), B3 = c(4768L, 4840L,
4936L, 4320L, 4388L, 4572L, 4640L, 4704L, 4696L, 4488L, 4396L,
4002L, 4030L, 3960L, 3684L, 3680L, 3896L, 4212L, 4364L, 4508L,
4732L, 4896L, 4848L, 4872L, 4960L, 5052L, 4848L, 4308L, 4800L,
5216L, 5224L, 5248L, 5136L, 4720L, 4428L, 4120L, 3918L, 4052L,
4058L, 3806L, 3802L, 3930L, 4092L, 4324L, 4476L, 4604L, 4768L,
4980L, 5080L, 5288L, 4840L, 4936L, 5096L, 5040L, 5096L, 5292L,
5280L, 5360L, 5480L, 5584L, 5528L, 5524L, 5700L, 5736L, 5732L,
6136L, 5980L, 5884L, 5904L, 5820L, 5864L, 6488L, 6572L, 6476L,
6256L, 6024L, 5844L, 5884L, 6100L, 6684L, 6596L, 6376L, 6188L,
5952L, 6044L, 6212L, 6268L, 6668L, 6484L, 6336L, 6164L, 6332L,
6432L, 6396L, 6592L, 6548L, 6500L, 6464L, 6460L, 7008L), B4 = c(4960L,
4964L, 4540L, 4164L, 4412L, 4608L, 4628L, 4588L, 4416L, 4312L,
4372L, 3806L, 3652L, 3570L, 3480L, 3708L, 3886L, 4188L, 4284L,
4344L, 4704L, 4776L, 4772L, 4980L, 5000L, 4852L, 4508L, 4916L,
5356L, 5400L, 5268L, 5156L, 4620L, 4324L, 4016L, 3884L, 3854L,
3854L, 3770L, 3562L, 3708L, 3854L, 4084L, 4228L, 4440L, 4532L,
4784L, 5008L, 5292L, 5464L, 4868L, 4996L, 4908L, 4932L, 5060L,
5136L, 5280L, 5444L, 5492L, 5500L, 5560L, 5604L, 5704L, 5660L,
5716L, 5892L, 5844L, 5796L, 5752L, 5816L, 5892L, 6500L, 6488L,
6212L, 5928L, 5796L, 5876L, 6084L, 6284L, 6660L, 6424L, 6088L,
6004L, 6044L, 6268L, 6336L, 6664L, 6500L, 6308L, 6152L, 6288L,
6424L, 6376L, 6860L, 6464L, 6500L, 6508L, 6468L, 7144L, 7652L
), B5 = c(5554L, 5554L, 4782L, 4736L, 4736L, 5018L, 5018L, 4968L,
4968L, 4677L, 4677L, 3814L, 3667L, 3667L, 3594L, 3975L, 3975L,
4348L, 4348L, 4736L, 4736L, 5018L, 5018L, 4968L, 4968L, 4677L,
4677L, 4930L, 5524L, 5524L, 5229L, 5229L, 4424L, 4424L, 4113L,
4113L, 4069L, 4069L, 3857L, 3932L, 3932L, 4228L, 4228L, 4591L,
4591L, 4918L, 4918L, 5324L, 5324L, 5543L, 5327L, 5327L, 5301L,
5471L, 5471L, 5301L, 5471L, 5471L, 5846L, 5977L, 5977L, 5899L,
5899L, 6099L, 6099L, 5977L, 5977L, 5899L, 5899L, 6099L, 6099L,
6857L, 6517L, 6517L, 6220L, 6220L, 6418L, 6418L, 6969L, 6517L,
6517L, 6220L, 6220L, 6418L, 6418L, 6969L, 6969L, 6861L, 6581L,
6581L, 6729L, 6729L, 7265L, 7265L, 6581L, 6729L, 6729L, 7265L,
7265L, 8025L), B6 = c(5249L, 5249L, 4428L, 4553L, 4553L, 4832L,
4832L, 4741L, 4741L, 4428L, 4428L, 3736L, 3464L, 3464L, 3509L,
3894L, 3894L, 4270L, 4270L, 4553L, 4553L, 4832L, 4832L, 4741L,
4741L, 4428L, 4428L, 5030L, 5441L, 5441L, 4926L, 4926L, 4146L,
4146L, 3907L, 3907L, 3910L, 3910L, 3721L, 3831L, 3831L, 4201L,
4201L, 4509L, 4509L, 4871L, 4871L, 5235L, 5235L, 5217L, 5207L,
5207L, 5087L, 5290L, 5290L, 5087L, 5290L, 5290L, 5777L, 5721L,
5721L, 5746L, 5746L, 5982L, 5982L, 5721L, 5721L, 5746L, 5746L,
5982L, 5982L, 6504L, 6116L, 6116L, 5946L, 5946L, 6257L, 6257L,
6916L, 6116L, 6116L, 5946L, 5946L, 6257L, 6257L, 6916L, 6916L,
6407L, 6293L, 6293L, 6545L, 6545L, 7197L, 7197L, 6293L, 6545L,
6545L, 7197L, 7197L, 7998L), B7 = c(4893L, 4893L, 4138L, 4527L,
4527L, 4681L, 4681L, 4505L, 4505L, 4170L, 4170L, 3629L, 3388L,
3388L, 3545L, 3982L, 3982L, 4288L, 4288L, 4527L, 4527L, 4681L,
4681L, 4505L, 4505L, 4170L, 4170L, 5127L, 5268L, 5268L, 4703L,
4703L, 3996L, 3996L, 3775L, 3775L, 3713L, 3713L, 3594L, 3813L,
3813L, 4166L, 4166L, 4462L, 4462L, 4836L, 4836L, 5277L, 5277L,
4910L, 5235L, 5235L, 5001L, 5241L, 5241L, 5001L, 5241L, 5241L,
5688L, 5539L, 5539L, 5599L, 5599L, 5988L, 5988L, 5539L, 5539L,
5599L, 5599L, 5988L, 5988L, 6278L, 5864L, 5864L, 5931L, 5931L,
6177L, 6177L, 6896L, 5864L, 5864L, 5931L, 5931L, 6177L, 6177L,
6896L, 6896L, 6212L, 6159L, 6159L, 6382L, 6382L, 7383L, 7383L,
6159L, 6382L, 6382L, 7383L, 7383L, 7856L), B8 = c(4836L, 4840L,
5044L, 4074L, 4236L, 4404L, 4592L, 4668L, 4796L, 4628L, 4632L,
3914L, 3896L, 3796L, 3580L, 3598L, 3596L, 3830L, 4096L, 4320L,
4460L, 4648L, 4904L, 4980L, 4940L, 5148L, 5180L, 4164L, 4628L,
5304L, 5512L, 5592L, 5500L, 5216L, 4732L, 4380L, 4036L, 4008L,
3994L, 3784L, 3660L, 3650L, 3794L, 4018L, 4212L, 4296L, 4516L,
4648L, 4908L, 5148L, 4876L, 4828L, 4936L, 4992L, 5052L, 5236L,
5236L, 5336L, 5380L, 5708L, 5648L, 5624L, 5580L, 5724L, 5796L,
6280L, 6156L, 6012L, 5876L, 5864L, 5868L, 6488L, 6636L, 6752L,
6612L, 6268L, 5924L, 5968L, 6092L, 6752L, 6876L, 6764L, 6484L,
6176L, 6108L, 6300L, 6460L, 6924L, 6724L, 6528L, 6484L, 6352L,
6500L, 6600L, 6784L, 6876L, 6676L, 6616L, 6732L, 6896L), B8A = c(4679L,
4679L, 4098L, 4524L, 4524L, 4643L, 4643L, 4460L, 4460L, 3987L,
3987L, 3413L, 3294L, 3294L, 3490L, 3840L, 3840L, 4140L, 4140L,
4524L, 4524L, 4643L, 4643L, 4460L, 4460L, 3987L, 3987L, 5232L,
5152L, 5152L, 4421L, 4421L, 3863L, 3863L, 3697L, 3697L, 3561L,
3561L, 3558L, 3788L, 3788L, 4110L, 4110L, 4493L, 4493L, 4894L,
4894L, 5032L, 5032L, 4606L, 5209L, 5209L, 4889L, 5233L, 5233L,
4889L, 5233L, 5233L, 5787L, 5324L, 5324L, 5492L, 5492L, 6018L,
6018L, 5324L, 5324L, 5492L, 5492L, 6018L, 6018L, 5872L, 5544L,
5544L, 5876L, 5876L, 6279L, 6279L, 6963L, 5544L, 5544L, 5876L,
5876L, 6279L, 6279L, 6963L, 6963L, 6134L, 6187L, 6187L, 6547L,
6547L, 7280L, 7280L, 6187L, 6547L, 6547L, 7280L, 7280L, 7968L
), B9 = c(6752L, 6752L, 6752L, 7098L, 7098L, 7098L, 7098L, 6752L,
6752L, 6752L, 6752L, 4997L, 5626L, 5626L, 5626L, 5626L, 5626L,
7098L, 7098L, 7098L, 7098L, 7098L, 7098L, 6752L, 6752L, 6752L,
6752L, 5698L, 5698L, 5698L, 5698L, 5698L, 5408L, 5408L, 5408L,
5408L, 5408L, 5408L, 5685L, 5685L, 5685L, 5685L, 5685L, 6352L,
6352L, 6352L, 6352L, 6352L, 6352L, 5794L, 8407L, 8407L, 7048L,
8407L, 8407L, 7048L, 8407L, 8407L, 8407L, 7048L, 7048L, 8407L,
8407L, 8407L, 8407L, 7048L, 7048L, 8407L, 8407L, 8407L, 8407L,
8487L, 8487L, 8487L, 9610L, 9610L, 9610L, 9610L, 9610L, 8487L,
8487L, 9610L, 9610L, 9610L, 9610L, 9610L, 9610L, 8487L, 9610L,
9610L, 9610L, 9610L, 9610L, 9610L, 9610L, 9610L, 9610L, 9610L,
9610L, 10128L), B10 = c(4170L, 4170L, 3407L, 3301L, 3301L, 3612L,
3612L, 3600L, 3600L, 3352L, 3352L, 2502L, 2388L, 2388L, 2403L,
2659L, 2659L, 2979L, 2979L, 3301L, 3301L, 3612L, 3612L, 3600L,
3600L, 3352L, 3352L, 3856L, 4192L, 4192L, 3840L, 3840L, 3187L,
3187L, 2782L, 2782L, 2634L, 2634L, 2501L, 2562L, 2562L, 2792L,
2792L, 3068L, 3068L, 3405L, 3405L, 3816L, 3816L, 3858L, 3343L,
3343L, 3188L, 3438L, 3438L, 3188L, 3438L, 3438L, 3774L, 3543L,
3543L, 3653L, 3653L, 3934L, 3934L, 3543L, 3543L, 3653L, 3653L,
3934L, 3934L, 4224L, 3999L, 3999L, 3881L, 3881L, 4162L, 4162L,
4724L, 3999L, 3999L, 3881L, 3881L, 4162L, 4162L, 4724L, 4724L,
4293L, 4161L, 4161L, 4380L, 4380L, 5052L, 5052L, 4161L, 4380L,
4380L, 5052L, 5052L, 5756L), B11 = c(3124L, 3124L, 2514L, 2969L,
2969L, 3137L, 3137L, 2922L, 2922L, 2487L, 2487L, 1850L, 1822L,
1822L, 2014L, 2309L, 2309L, 2600L, 2600L, 2969L, 2969L, 3137L,
3137L, 2922L, 2922L, 2487L, 2487L, 3753L, 3535L, 3535L, 2823L,
2823L, 2296L, 2296L, 2151L, 2151L, 1974L, 1974L, 1924L, 2100L,
2100L, 2386L, 2386L, 2731L, 2731L, 3087L, 3087L, 3380L, 3380L,
3006L, 2740L, 2740L, 2443L, 2800L, 2800L, 2443L, 2800L, 2800L,
3228L, 2669L, 2669L, 2935L, 2935L, 3338L, 3338L, 2669L, 2669L,
2935L, 2935L, 3338L, 3338L, 3049L, 2893L, 2893L, 3087L, 3087L,
3550L, 3550L, 4235L, 2893L, 2893L, 3087L, 3087L, 3550L, 3550L,
4235L, 4235L, 3184L, 3242L, 3242L, 3774L, 3774L, 4487L, 4487L,
3242L, 3774L, 3774L, 4487L, 4487L, 5217L), B = c(20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L), E = c(20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L), C = c(20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L), OC = c(30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L
), OLS = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L)), class = "data.frame", row.names = c(NA, -100L
))
p
library(gbm)
#> Loaded gbm 2.1.8
dependend <- c("B", "E", "C", "OC", "OLS")
mylistwithdepended_vars <- mget(dependend, envir = as.environment(new))
fun <- function(Value){
gbm.fit.final109 <- gbm(
formula = Value ~ .,
distribution = "gaussian",
data = new,
n.trees = 483,
interaction.depth = 5,
shrinkage = 0.1,
n.minobsinnode = 5,
bag.fraction = .65,
train.fraction = 1,
n.cores = NULL, # will use all cores by default
verbose = FALSE
)
}
gbm_models <- Map(fun, mylistwithdepended_vars)
old_par <- par(mfrow = c(1, 5))
mapply(summary, gbm_models, main = names(gbm_models))
Therefore, the question is how to supplement the result of the models in order to provide for each of the obtained gbm models.
1. mape and
2 predictions was and predicted?
I would see it like this
MAPE
model1 1%
model2 2%
model1(OLS)
was predict
34 32
35 33
model2(b)
was pred
10 9
11 12
is there a way to achieve this desired result?

How to get the n most common items in each group

I'm trying to make a plot, where for each chapter in a book it shows the most common words for that chapter. The problem I'm having is that I'm using the top_n function with a value of 10, but I'm not getting exactly 10 in each facet. Also I would like to know what is the difference here between using count and add_count. Here is the plot:
And the code:
library(tidytext)
library(tidyverse)
notw_processed %>%
filter(chapter < 13) %>%
count(chapter, word) %>%
group_by(chapter) %>%
top_n(10, n) %>%
ungroup() %>%
mutate(word = as_factor(word)) %>%
mutate(word = reorder_within(word, n, chapter)) %>%
ggplot(aes(x = word, y = n)) + geom_col() + coord_flip() +
facet_wrap(~chapter, scale = "free_y") + scale_x_reordered()
And a sample from the data:
dput(notw_processed[sample(1:50000, size = 200, replace = FALSE),])
structure(list(linenumber = c(1884L, 3131L, 41L, 2756L, 1011L,
538L, 3312L, 1856L, 2764L, 2691L, 3702L, 505L, 2090L, 2796L,
1811L, 270L, 228L, 3088L, 3262L, 778L, 1446L, 1696L, 1839L, 1413L,
3961L, 1375L, 306L, 895L, 1647L, 2037L, 822L, 2412L, 3266L, 1287L,
3919L, 3900L, 141L, 1628L, 1459L, 465L, 3309L, 193L, 60L, 4040L,
3276L, 3522L, 682L, 1338L, 394L, 2023L, 2929L, 3239L, 808L, 160L,
206L, 2173L, 3818L, 203L, 383L, 1443L, 1693L, 645L, 1535L, 1974L,
1557L, 3931L, 1877L, 1683L, 1154L, 1601L, 3548L, 1959L, 1625L,
777L, 704L, 3054L, 2152L, 3624L, 2968L, 2035L, 1621L, 2275L,
3625L, 805L, 2731L, 1334L, 2460L, 2294L, 684L, 896L, 371L, 1837L,
2009L, 903L, 1020L, 3300L, 1504L, 1495L, 611L, 2208L, 2277L,
2025L, 1991L, 584L, 1590L, 1468L, 610L, 2683L, 1697L, 156L, 2640L,
3507L, 1975L, 163L, 2807L, 2285L, 1687L, 219L, 4069L, 3983L,
1365L, 176L, 653L, 2226L, 4020L, 3841L, 1915L, 1455L, 486L, 3881L,
2596L, 2252L, 1248L, 3879L, 364L, 2176L, 2304L, 2900L, 75L, 2488L,
1852L, 3504L, 1547L, 2713L, 1574L, 3275L, 3061L, 3368L, 3628L,
3883L, 1701L, 3637L, 3781L, 3042L, 836L, 354L, 2934L, 1781L,
1964L, 113L, 1707L, 2609L, 2066L, 1882L, 3841L, 2362L, 3894L,
466L, 2296L, 1230L, 2250L, 1816L, 3947L, 1668L, 139L, 1872L,
3296L, 2878L, 206L, 2336L, 3852L, 730L, 3956L, 2311L, 373L, 17L,
83L, 626L, 936L, 2165L, 2686L, 4030L, 1582L, 1120L, 1761L, 1002L,
40L, 734L, 3733L, 3933L), chapter = c(23L, 41L, 1L, 37L, 12L,
6L, 43L, 23L, 37L, 37L, 49L, 6L, 27L, 38L, 23L, 3L, 2L, 40L,
43L, 9L, 17L, 22L, 23L, 16L, 52L, 16L, 3L, 11L, 21L, 26L, 10L,
33L, 43L, 15L, 52L, 52L, 1L, 20L, 18L, 5L, 43L, 2L, 1L, 53L,
43L, 46L, 8L, 16L, 4L, 26L, 39L, 43L, 9L, 1L, 2L, 29L, 50L, 2L,
4L, 17L, 22L, 8L, 20L, 26L, 20L, 52L, 23L, 22L, 14L, 20L, 46L,
26L, 20L, 9L, 8L, 40L, 28L, 46L, 40L, 26L, 20L, 31L, 46L, 9L,
37L, 16L, 35L, 31L, 8L, 11L, 3L, 23L, 26L, 11L, 12L, 43L, 19L,
19L, 7L, 30L, 31L, 26L, 26L, 7L, 20L, 18L, 7L, 37L, 22L, 1L,
36L, 45L, 26L, 1L, 38L, 31L, 22L, 2L, 53L, 52L, 16L, 1L, 8L,
31L, 53L, 51L, 24L, 18L, 6L, 52L, 36L, 31L, 14L, 52L, 3L, 29L,
32L, 39L, 1L, 35L, 23L, 45L, 20L, 37L, 20L, 43L, 40L, 43L, 46L,
52L, 22L, 46L, 50L, 40L, 10L, 3L, 39L, 23L, 26L, 1L, 22L, 36L,
26L, 23L, 51L, 32L, 52L, 5L, 31L, 14L, 31L, 23L, 52L, 21L, 1L,
23L, 43L, 38L, 2L, 32L, 51L, 8L, 52L, 32L, 3L, 1L, 1L, 7L, 12L,
29L, 37L, 53L, 20L, 13L, 22L, 12L, 1L, 8L, 50L, 52L), word = c("choose",
"remember", "demon", "manet", "question", "remembering", "finally",
"times", "marks", "false", "approach", "plum", "unable", "head",
"treated", "kote", "chronicler", "method", "locate", "thousand",
"blinding", "hat", "world", "cinder’s", "rallying", "crack",
"building", "expecting", "wrong", "sow", "god", "husband", "fela",
"counter", "wil", "lump", "stew", "ate", "deep", "forehead",
"untarnished", "horse", "west", "series", "archives", "thumb",
"folk", "slight", "don’t", "leaden", "candle’s", "books", "powerful",
"banished", "dried", "spoken", "you’re", "shape", "limping",
"earlier", "customers", "eager", "wagon", "looked", "strangely",
"yesterday", "finally", "frightening", "indignantly", "bit",
"front", "pints", "squash", "taborlin", "trouble", "whipped",
"skarpi", "command", "smile", "considered", "lay", "purse", "eyes",
"symptoms", "tin", "troupers", "luggage", "penny", "bright",
"bricks", "nodded", "mother", "dead", "imply", "should’ve", "front",
"broke", "play", "story", "pulled", "found", "lay", "skarpi",
"knowing", "smelled", "knots", "chronicler", "worth", "shouted",
"stew", "pennies", "university", "pennies", "fine", "boy", "smells",
"sound", "chronicler", "crescent", "stay", "proper", "soldiers",
"tables", "shirt", "hoping", "riot", "boy", "time", "scribe",
"prove", "sync", "haven’t", "talking", "tired", "smith’s", "half",
"half", "plainly", "it’s", "called", "knees", "beck", "wouldn’t",
"tray", "worth", "physically", "moment", "simmon", "simply",
"meat", "forward", "impressive", "scarred", "ayes", "don’t",
"street", "friends", "tanee", "friends", "eyes", "looked", "namer",
"story", "eyes", "mains", "expressions", "shop", "listening",
"lucky", "words", "half", "wicked", "candle", "fever", "fidget",
"shook", "mind", "law", "incredibly", "favor", "grate", "read",
"fierce", "urchin", "they’re", "broke", "chair", "call", "transferred",
"remembered", "tarbean’s", "heard", "hot", "chronicler", "size",
"silly", "wary", "mended", "thin", "dal")), row.names = c(NA,
-200L), class = c("tbl_df", "tbl", "data.frame"))
As pointed out by #StupidWolf, in case of a tie then top_n returns all the ties, so it doesn't have to return exactly 10 cases.
notw_processed %>%
filter(chapter < 13) %>%
count(chapter, word) %>%
group_by(chapter) %>%
top_n(10, n) %>%
slice(1:10) %>%
ungroup() %>%
mutate(word = as_factor(word)) %>%
mutate(word = reorder_within(word, n, chapter)) %>%
ggplot(aes(x = word, y = n)) + geom_col() + coord_flip() +
facet_wrap(~chapter, scale = "free") + scale_x_reordered()
By grouping by chapter and slicing after the top_n call, I can ensure it will be exactly 10 values per facet.

Apply function to data grouped by cut()

I would like some help with summarising data using cut. I have been successful in less complicated situations, but now I am stuck.
The data:
> dput(sumsq)
structure(list(part_no = c(10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), ratperc = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0, 0, 0, 0,
0, 0, 75.6, 0, 89.6, 24.8, -100, -100, 75.6, 100, 100, -100,
-100, -100, -100, -100, -100, 75.6, 98.4, 98.4, -51.2, -51.2,
0.8, 0.8, 0.4, 0.4, 0.4, 0.4, 75.2, -100, -100, -100, 1.2, -0.4,
-0.4, -0.4, -0.4, 100, 100, -1.6, 0, 0, 0, 0, -100, 0.4, 100,
0.4, 0.4, 100, -0.4, -78.4, 0.4, 100, 100, 100, 100, -100, 23.6,
61.2, 61.2, 69.2, 75.6, 75.6, 75.6, 75.6, 75.6, 98, 98, 98, -75.2,
-75.2, 47.2, 47.2, 47.2, 47.2, 76.8, 97.6, -71.6, -71.6, -71.6,
-71.6, 24, 52, 52, 52, 75.2, 75.2, -77.6, 25.2, 47.2, 76.4, 76.4,
76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4,
76.4, -73.2, -73.2, -73.2, -73.2, 0.8, 0.8, 75.2, 75.2, 75.2,
75.2, 75.2, 75.2, 0.4, 0.4, 0.4, 0.4, 0.4, -100, -100, -100,
-100, -100, 73.2, 2, -0.8, -0.8, -0.8, -100, -0.4, -0.4, 50.4,
50.4, 50.4, 50.4, 50.4, 50.4, -76.4, 99.6, 99.6, -76.4, 100,
100, 50.4, 1.2, 28, -1.2, 93.6, 41.2, 1.6, 24.8, -1.6, 0, 0,
24.8, -24, 26, 50.8, 2, 28, 36.4, 24, -43.6, 33.6, 61.2, 81.2,
86.8, 34, -51.6, -2, 28.4, 2, 82, 41.6, 25.6, 82, 0.8, 92, 1.2,
86.4, 54, 96, 0.4, -54.4, 1.2, -93.2, -49.2, -98.4, -2, -77.2,
93.2, 23.6, 78.8, 42.4, 0.4, 2.8, 70.8, 24.4, 2.4, 62, 92.8,
16.4, -61.2, 24.4, -77.2, -0.4, 74.8, 3.6, 82, 82, 18, 54, 9.2,
55.2, 96.4, 96.4, 90, 90, -84.4, -84.4, -2.8, -2, -90.4, 2.4,
34.8, 24, -1.6, -16.8, 2.8, 2.4, -83.2, 22.4, 22.4, -1.6, -1.6,
60, -2.4, 2.4, 2, 0.8, -22.8, 2, -1.6, 25.2, 2, 2, -52.8, -1.2,
-1.2, 3.2, -74.4, 3.2, 3.2, -78.4, 0.4, -2.4, 0.4, 0.4, 0.4,
0.4, 0.4, 0.4, -79.2, -0.8, -0.8, -0.8, -0.8, -0.8, -3.2, 41.2,
-0.8, -0.8, -0.8, -0.8, -83.2, -1.6, -1.6, 0.4, 0.4, 0.4, -90,
-1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6,
77.6, -79.6, 80.8, -81.6, -93.2, -100, 8.4, 75.6, 82.8, 67.2,
-27.2, 78.8, 65.6, 84.8, 73.6, 46.8, -62.4, 57.2, 74, 13.6, -0.8,
32.8, -27.2, 6.4, -67.2, 79.2, -64, 58, -40.4, 64, 8, 60, 76.8,
-24.8, -52.4, 56.8, 75.6, 38.4, -50.4, -72.8, -83.6, 24, 34.8,
54.4, -54, 67.6, 78.4, -41.6, -64.4, -83.6, -93.6, 76.8, -2.4,
-19.2, -54, -38, 5.2, 52.4, 64.8, 42.4, 77.6, -46.4, -74.8, -60.4,
-83.2, -56.4, -34.8, -16.8, 21.2, 40, 59.2, 0.4, -17.6, 24.4,
-14.4, 35.2, -26.8, 42, 44, -1.2, -35.6, 10.8, -19.6, -35.2,
22.4, -18.4, 27.6, -9.6, 43.2, -31.2, 45.2, 23.6, -16.4, 28.8,
40.4, 25.6, -8, 15.6, 11.2, -17.2, 15.6, -17.6, 18, 24, -9.6,
-34.8, 12.4, -17.2, 36.4, -9.2, -35.2, -19.6, 10.4, -15.6, -30.4,
30.8, 16.4, -14.8, -26.4, -34.4, 52.8, 34.4, 55.6, 21.2, 41.2,
52, 36.8, 50, 15.6, 36, 53.6, -22.8, 14.8, 25.2, -13.2, -18.8,
32, 20.8, -6.8, -16.4, -27.6, 14.4, 26.8, 38, -28.4, 19.6, -23.6,
18.4, -19.6, 11.6, 0, 0, 0, -26, -52.4, -24.4, 2, 19.6, -10.8,
3.6, 3.6, -25.2, 28.4, 12, -11.2, 3.2, 37.2, 26, 0.8, 47.6, -17.2,
2.4, -12, -52.4, 0.8, 28.4, -12, 36.4, 2.4, 50.4, -16, 24.4,
-2.4, -2.4, 15.2, -1.6, -1.6, -1.6, 24.4, -36, 33.2, 1.2, 1.2,
-48.8, -22.4, -1.2, -100, -1.6, -1.6, -26.4, 28, -47.6, 86, -1.6,
-1.6, -1.6, -1.6, -1.6, 41.6, -16, 29.6, -14.8, 3.2, 3.2, 100,
0.8, 0.8, 0.8, 0.8, 25.6, 24.8, -28, 0.8, -39.2, -97.6, -97.6,
-50, 0, 0, 49.6, 0.8, 54, 25.6, -1.2, -1.2, -90.8, 4.4, 4.4,
41.6, -40.8, -6, -6, 51.6, -8.4, 0, 0, 0, -60, 2.8, -52.4, 1.6,
1.6, 1.6, 18.8, 24.4, -0.4, -0.4, -0.4, -0.4, -51.6, -0.4, -0.4,
-0.4, 26, 0, 18, -42.4, -1.6, -0.4, 60.4, -2.8, -2.8, -2.8, 76,
2.8, 2.8, -29.2, -23.2, 23.6, -26.8, 0.4, 0.4, -40.8, -3.6, -47.6,
27.6, -2.4, -2.4, -76, -2, -2, -2, -30.8, 26.8, -4.4, -4.4, -4.4,
3.6, -0.8, -0.8, 67.2, -1.2, -48.8, 63.2, -42, 50, 30.8, 57.6,
-48.8, -48.8, 41.6, -39.2, -39.2, -35.6, 40, -44, -39.6, -39.6,
-50.8, 0, -48.8, 40, -53.2, 52, -47.2, -47.2, -46, 26.4, -29.2,
0, -46.8, -46.8, 34.8, -43.6, 0, 39.2, 0.4, -48.4, 0, -23.6,
29.2, 29.2, -53.2, -53.2, 19.2, 46.4, 46.4, -2, 36, 2, -25.2,
-50, -1.6, -2, 35.2, -32.8, 31.2, -43.2, 46, -28.8, -0.4, -50.4,
0.8, -43.6, 0.4, 27.6, -37.6, -37.6, 37.6, -50, 40.8, -0.8, -50.4,
-49.6, 45.6, 45.6, -48.8, -0.8, -54, -54, 43.2, -48.8, 46.4,
-42.8, 54, -54.4, 34.8, 0.4, 0.4, 0.4, 0.8, -50.4, -50.8, -50.8,
51.6, -68.8, 0.8, 52, -42, -42, 0, -56.8, -56.8, 0.8, -48, -46.4,
-46.8, -46.8, 0.4, 0.4, 37.2, -36.8, -36.8, -0.4, -0.4, -0.4,
-0.4, -0.4, -48.8, 0.8, 0.8, 58.8, 2, 2, 2, 2, 29.2, -50.4, 49.6,
41.2, -39.2, 38.8, -38.8, 28, -38, 40.8, 0.8, 0.8, 0.8, 0.8,
0.8, -51.2, 27.2, -54.8, 0.8, 0.8, -40.4, -40.4, 0, -46.8, 35.2,
-50.4, 9.6, -0.4, -15.2, 17.6, -26.8, -14.4, 42.8, 18.8, 2.8,
0, -33.2, -36.4, -7.6, 18.8, 34.4, 8.8, -25.6, -16.8, -10, -50.8,
10, -11.2, -7.2, -15.2, -62.8, 27.6, -12.8, -1.2, -24.4, 18.8,
-7.2, 37.2, 8.4, -40, -9.6, 20, -27.2, 27.2, 7.2, -31.6, -31.6,
27.6, -1.6, -20, -20, 34.4, 18, -23.6, 28.4, -16, 15.2, -30.4,
-9.2, -7.6, 12.4, 23.2, 15.6, 23.2, 37.2, -8.8, -21.6, -31.6,
-23.2, 25.2, 33.2, 9.2, 34.4, 18, 5.2, -50.4, 34.8, 12.4, -13.6,
-7.2, 6.4, 15.2, 2, 12.8, -14.4, 32.4, 15.6, 23.2, 30, -11.6,
-34.8, 12, -24, -11.2, -41.2, 34.4, 18.8, 18.8, 12, 37.6, 10,
35.2, -24.4, 24.8, 40.4, 52.4, 14, -41.6, 34, 43.2, -6, -28,
24, 35.2, 26.8, -15.2, 28, 38.8, 11.6, 57.6, 28, 12, -18.8, 35.6,
25.2, 40.4, 59.2, -58.4, 10.4, -23.6, 18, -14, 35.2, 13.6, 48.4,
32.8, 32.8, -17.2, -11.2, 26, -24, 15.2, -66.4, 24.4, -30.4,
39.6, 30, 53.2, 59.6, -40.4, -14, 36, 36, 41.6, 32, 57.6, 8.4,
62, 85.6, 85.6, 84.4, 38, 63.2, 67.2, -42.8, 63.6, 95.2, 65.2,
86.8, 87.2, 9.2, 83.2, 11.6, 83.2, 83.2, 79.6, 63.2, 88.8, -62,
-84.8, -84.8, -86.8, -4.4, 87.2, 86, 17.2, 81.6, -60.8, -87.6,
80, 37.2, -64.8, 86.4, 87.2, 94.4, 94, -61.6, 86.8, 86.4, 86.8,
86, -86, 94.4, -87.6, 80, 84.8, 86.8, -64.8, 85.2, 83.2, -90.8,
88.8, 85.6, 85.2, 87.2, 85.2, 85.6, -64, 84.8, 84.4, -90, 84.8,
82, -83.6, 88.4, 92, 80.8, 79.6, 80.4, 78.4, 78.4, 80, 80, 79.2,
81.2, 84.8, -78.4, 80.8, -88.8, 81.6, 81.6, -64.8, -85.6, 89.2,
90.4, -84, 85.2, -32.8, 49.6, 83.2, 81.2, 79.2, 80, 85.6, 81.6,
34.4, -85.6, 83.6, 82.4, 84, 81.2, 85.6, 85.6, 87.6, 84.8, 85.6,
82.8, -86.4, -60, 36.8, -85.6, 86.4, -65.6, 81.6, -81.2, 92.8,
-86.4, 84.8, 63.2, 36, 86.4, 86.4, 82.4, 83.2, 82.8, 82.4, 80.8,
80.4, 80.4, -63.6, 84.8, 84.8, 68, 93.2, 88, 89.6, 33.6, 83.6,
-67.2, 88.8, 88, 85.2, -39.6, 84.8), diffdist = c(-9L, -7L, -16L,
-17L, -38L, 55L, -17L, -2L, -18L, -24L, -7L, 24L, -40L, -35L,
69L, -42L, -15L, 80L, 73L, -28L, 39L, -46L, 40L, -49L, 11L, -9L,
-6L, -50L, 71L, 23L, -69L, -1L, 8L, 37L, -29L, -16L, 25L, -8L,
-44L, 27L, -20L, -11L, 16L, -16L, 40L, -57L, -13L, 13L, 40L,
-7L, 51L, -19L, -2L, -9L, 22L, 35L, -13L, -20L, -4L, -64L, 0L,
-48L, -55L, -19L, 20L, 6L, 31L, 9L, -62L, -4L, -50L, 39L, 53L,
-22L, 33L, 58L, 62L, -37L, 5L, -5L, 36L, 35L, -9L, 16L, -42L,
-20L, 7L, 24L, 29L, -80L, 41L, -18L, -28L, -16L, 6L, 15L, -37L,
52L, -12L, -40L, 64L, -28L, 22L, 29L, -4L, -47L, -3L, -61L, -2L,
21L, 3L, 9L, 35L, 73L, -20L, -8L, -53L, -19L, -11L, -6L, -56L,
17L, -20L, -66L, -16L, -29L, 26L, -29L, 44L, 38L, 40L, 51L, 84L,
-33L, -33L, -6L, -71L, -14L, -13L, -47L, 21L, 5L, -9L, -42L,
-26L, 35L, 53L, 2L, -6L, 31L, -22L, -70L, -17L, 35L, -55L, 9L,
-14L, 2L, 11L, -71L, 49L, 30L, -40L, -77L, 15L, 53L, -29L, 51L,
68L, -5L, -24L, -75L, -60L, -27L, -43L, -5L, -3L, -31L, -22L,
8L, -43L, 9L, -43L, -35L, 70L, -47L, -23L, 25L, -64L, 0L, -24L,
-17L, 68L, -12L, -57L, 28L, -9L, 42L, 35L, 21L, 13L, 9L, -9L,
-12L, 31L, -6L, -8L, -33L, 20L, -4L, -53L, 37L, -33L, 21L, 68L,
-28L, -56L, 61L, -69L, -12L, 9L, -23L, -60L, -9L, -7L, 45L, -44L,
-33L, 47L, -7L, 53L, -2L, -13L, -18L, 57L, -2L, 45L, 40L, -18L,
9L, -21L, 22L, 4L, 27L, 27L, -63L, -62L, -59L, 13L, -3L, -62L,
2L, 23L, 52L, 20L, -18L, 52L, 40L, -51L, -24L, -18L, -29L, -47L,
-33L, 64L, -74L, -36L, 18L, -36L, 22L, 8L, -46L, 24L, 4L, -74L,
-3L, 18L, -53L, 20L, 60L, -9L, -19L, 15L, 31L, 18L, 35L, 24L,
11L, -40L, -64L, 33L, -31L, 8L, 58L, 41L, -33L, -53L, -35L, 2L,
-19L, 42L, -53L, 64L, 46L, -53L, 62L, -77L, -18L, -3L, -11L,
33L, -67L, 68L, 0L, 51L, 13L, -11L, 40L, -65L, 22L, 39L, -5L,
76L, -44L, -35L, 15L, 0L, 13L, 7L, 6L, -51L, -44L, -20L, 20L,
11L, -55L, -66L, -49L, 4L, -58L, -27L, 20L, -16L, 42L, -69L,
71L, -68L, -42L, 44L, 31L, -13L, -63L, -72L, -13L, 19L, 39L,
-13L, 71L, -53L, -33L, 67L, -42L, 14L, 39L, 33L, -13L, -19L,
73L, -71L, -24L, 11L, 0L, -42L, -71L, -1L, -62L, -11L, -7L, 18L,
49L, 8L, -21L, -5L, 13L, -38L, 62L, -15L, -27L, 0L, -33L, 9L,
-40L, -57L, 60L, 73L, -24L, 0L, 22L, -37L, -46L, -27L, 27L, 0L,
6L, 77L, -13L, 47L, 71L, -20L, 11L, 18L, 31L, 8L, 80L, -87L,
-20L, 57L, -37L, 24L, 62L, -11L, -50L, 9L, 52L, 7L, 2L, -57L,
-50L, 69L, 7L, -42L, -43L, -22L, 46L, 57L, 24L, 35L, 9L, -54L,
51L, 6L, -8L, -8L, 9L, 48L, 24L, 31L, -55L, 53L, 44L, 7L, -7L,
22L, -53L, 42L, -44L, -2L, 6L, -9L, -5L, 33L, -20L, 20L, 36L,
39L, -16L, -25L, 44L, -28L, 4L, -4L, -47L, -87L, 6L, -38L, 51L,
-9L, 37L, -47L, 72L, -19L, 26L, 37L, -43L, 29L, -11L, 54L, 4L,
-41L, -24L, -55L, 11L, 35L, 22L, 57L, 61L, 40L, -52L, -17L, 10L,
28L, -24L, -28L, -3L, -9L, -47L, 40L, 35L, 57L, 13L, 13L, 33L,
24L, 22L, -67L, -49L, -77L, 7L, -36L, 9L, 29L, -16L, -5L, 11L,
-13L, 57L, -17L, 49L, 66L, -55L, -33L, -6L, -29L, 5L, -62L, 80L,
33L, 73L, 87L, -3L, 18L, 40L, 18L, 70L, 49L, 55L, 5L, -13L, 9L,
-17L, 36L, -22L, 9L, 0L, -75L, -40L, -12L, 17L, 19L, -9L, 13L,
-15L, -51L, 10L, -20L, 1L, 3L, 40L, 38L, 19L, 11L, 0L, 89L, -10L,
49L, 44L, 75L, 83L, -8L, 36L, -60L, 38L, -53L, -19L, 11L, 4L,
-53L, -51L, -11L, 71L, 20L, 7L, -33L, 37L, 3L, 49L, 22L, -57L,
-74L, -30L, 22L, 11L, -9L, -19L, -51L, -42L, 3L, 55L, -42L, -7L,
-19L, -53L, 32L, -73L, 11L, -9L, -31L, 20L, -5L, 55L, -26L, -22L,
-28L, 75L, -15L, -58L, 20L, 37L, -26L, -57L, -50L, -47L, -35L,
-20L, 22L, 1L, 28L, 0L, -38L, 24L, 40L, 22L, -33L, 34L, -28L,
-18L, 33L, -57L, 4L, -13L, -25L, -62L, 33L, -62L, 55L, 28L, -9L,
14L, -50L, -18L, -40L, 20L, 24L, -53L, -27L, 23L, 4L, 13L, 27L,
-55L, -4L, 44L, 4L, -9L, -17L, -44L, -42L, 18L, -33L, -44L, 17L,
-53L, -13L, -24L, -56L, -41L, 28L, 31L, 21L, -13L, 27L, -46L,
-50L, -25L, 29L, -7L, -6L, -11L, -18L, 71L, -69L, -50L, -3L,
2L, 18L, -24L, -40L, -15L, -46L, 11L, 29L, 10L, -30L, 7L, -13L,
50L, 77L, 2L, 9L, -71L, -9L, -62L, -55L, 29L, 38L, -48L, -22L,
-30L, 39L, -44L, 42L, -5L, -61L, 16L, 24L, -46L, 2L, 4L, -8L,
-16L, 33L, -35L, 80L, -39L, 19L, -55L, -23L, -46L, 2L, 7L, -77L,
-5L, 18L, -44L, -18L, -62L, -62L, -84L, 85L, 13L, 49L, 11L, 41L,
40L, -38L, 15L, 39L, -13L, 39L, -11L, -64L, 58L, 35L, -18L, 34L,
18L, 24L, -22L, -4L, -46L, -71L, 22L, -44L, -49L, -11L, -40L,
-4L, 11L, -5L, 37L, -24L, -27L, -33L, 52L, -11L, 9L, -54L, 0L,
-24L, 0L, 18L, 13L, -17L, 22L, 64L, 58L, 71L, -6L, -24L, 29L,
-3L, -22L, -9L, 55L, -9L, -16L, -35L, 56L, 25L, -58L, -26L, -9L,
62L, -48L, -62L, 9L, 35L, -8L, 33L, 40L, 55L, 40L, 35L, -23L,
11L, 46L, 62L, -15L, -2L, -9L, -17L, 39L, 15L, -13L, -37L, 20L,
-7L, -14L, 70L, 28L, -2L, 55L, -25L, 6L, -36L, 30L, 62L, 66L,
11L, 24L, -42L, 58L, 9L, 45L, 4L, 0L, -20L, 20L, 27L, -4L, 3L,
-40L, -2L, 2L, 10L, 8L, 20L, -24L, -39L, -13L, 20L, -45L, -76L,
-46L, 3L, -55L, -18L, 22L, 2L, -14L, -20L, -26L, 51L, -66L, -9L,
0L, 51L, 22L, -12L, 27L, -35L, 11L, 38L, -3L, 15L, 4L, -55L,
44L, -55L, -46L, 6L, -46L, 22L, 22L, 46L, 20L, 35L, -11L, -20L,
-53L, 51L, -80L, -59L, -53L, -78L, -36L, -13L, 31L, 33L, -9L,
-26L, 31L, -14L, -16L, -15L, -53L, 9L, 65L, 3L, 44L, -42L, 45L,
-13L, -7L, -6L, 52L, 60L, -3L, -3L, 7L, -40L, 2L, 29L, 11L, 33L,
40L, -16L, -9L, -21L, 78L, -60L, 15L, 0L, 17L, -15L, -18L, 48L,
26L, 31L, -53L, -9L, -3L, -1L, 64L, 7L, 44L, -38L, -23L, 13L,
55L, 57L, -71L, -20L, 23L, -18L, 4L, 16L, -7L, 52L, 42L, 24L,
5L, -2L, 6L, -33L, 9L, 30L, -51L, 58L, 53L, -44L, -22L, -44L,
-75L, -60L, 46L, 14L, 13L, -5L, -7L, 69L, -18L, 53L, 52L, -62L,
-13L, 22L, 64L, -18L, 71L, 24L, -9L, 68L, -40L, -10L, -2L, 12L,
37L, 40L, 79L, 3L, 42L, -55L, 7L, -31L, 20L, 16L, 7L, 11L, -14L,
70L, 24L, 3L, -57L, -14L, 51L, -19L, -62L, -16L, -2L, -68L, 4L,
7L, -20L, 4L, -15L, 49L, -16L, 11L, 6L, 56L, -6L, 68L, 28L, 33L,
-62L, 20L, -39L, -12L, -45L, -30L, -15L, 37L, 44L, 39L, 38L,
46L, 33L, 2L, -3L, 29L, 44L, 2L, -57L, 37L, 42L, 20L, 5L, 53L,
-51L, 11L, -5L, -24L, 7L, 29L, -20L, -15L, 24L, 80L, 4L, 82L,
29L, -24L, 68L, -38L, 27L, 71L, 30L, 42L, 14L, -75L, -41L, 22L,
46L, -72L, -53L, 78L, 54L, 22L, -55L, 57L, -1L, -54L, 80L, 68L,
-17L, -18L, -3L, 5L, 16L, -39L, -21L, -29L, -64L, -5L, 46L, -8L,
3L, -15L, 26L, -6L, 38L, -2L, -13L, -62L, -51L, -60L, 9L, -64L,
51L, 31L, 36L, 0L, -35L, 29L, 22L, 31L, -2L, 14L, 73L, -17L,
17L, -58L, 55L, 37L, -16L, 71L, 28L, 72L, -26L, 22L, 12L, 25L,
23L, -46L, -9L, -55L, -7L, 18L, -40L, 28L, -9L, 5L, -6L, 26L,
58L, 31L, -38L, -27L, 14L, -34L, -5L, 9L, 20L, -35L, 31L, -3L,
-19L, -33L, 34L)), .Names = c("part_no", "ratperc", "diffdist"
), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L,
64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L,
90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L,
102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L,
124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L,
146L, 147L, 148L, 149L, 150L, 301L, 302L, 303L, 304L, 305L, 306L,
307L, 308L, 309L, 310L, 311L, 312L, 313L, 314L, 315L, 316L, 317L,
318L, 319L, 320L, 321L, 322L, 323L, 324L, 325L, 326L, 327L, 328L,
329L, 330L, 331L, 332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L,
340L, 341L, 342L, 343L, 344L, 345L, 346L, 347L, 348L, 349L, 350L,
351L, 352L, 353L, 354L, 355L, 356L, 357L, 358L, 359L, 360L, 361L,
362L, 363L, 364L, 365L, 366L, 367L, 368L, 369L, 370L, 371L, 372L,
373L, 374L, 375L, 376L, 377L, 378L, 379L, 380L, 381L, 382L, 383L,
384L, 385L, 386L, 387L, 388L, 389L, 390L, 391L, 392L, 393L, 394L,
395L, 396L, 397L, 398L, 399L, 400L, 401L, 402L, 403L, 404L, 405L,
406L, 407L, 408L, 409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L,
417L, 418L, 419L, 420L, 421L, 422L, 423L, 424L, 425L, 426L, 427L,
428L, 429L, 430L, 431L, 432L, 433L, 434L, 435L, 436L, 437L, 438L,
439L, 440L, 441L, 442L, 443L, 444L, 445L, 446L, 447L, 448L, 449L,
450L, 601L, 602L, 603L, 604L, 605L, 606L, 607L, 608L, 609L, 610L,
611L, 612L, 613L, 614L, 615L, 616L, 617L, 618L, 619L, 620L, 621L,
622L, 623L, 624L, 625L, 626L, 627L, 628L, 629L, 630L, 631L, 632L,
633L, 634L, 635L, 636L, 637L, 638L, 639L, 640L, 641L, 642L, 643L,
644L, 645L, 646L, 647L, 648L, 649L, 650L, 651L, 652L, 653L, 654L,
655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 663L, 664L, 665L,
666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 674L, 675L, 676L,
677L, 678L, 679L, 680L, 681L, 682L, 683L, 684L, 685L, 686L, 687L,
688L, 689L, 690L, 691L, 692L, 693L, 694L, 695L, 696L, 697L, 698L,
699L, 700L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L,
710L, 711L, 712L, 713L, 714L, 715L, 716L, 717L, 718L, 719L, 720L,
721L, 722L, 723L, 724L, 725L, 726L, 727L, 728L, 729L, 730L, 731L,
732L, 733L, 734L, 735L, 736L, 737L, 738L, 739L, 740L, 741L, 742L,
743L, 744L, 745L, 746L, 747L, 748L, 749L, 750L, 901L, 902L, 903L,
904L, 905L, 906L, 907L, 908L, 909L, 910L, 911L, 912L, 913L, 914L,
915L, 916L, 917L, 918L, 919L, 920L, 921L, 922L, 923L, 924L, 925L,
926L, 927L, 928L, 929L, 930L, 931L, 932L, 933L, 934L, 935L, 936L,
937L, 938L, 939L, 940L, 941L, 942L, 943L, 944L, 945L, 946L, 947L,
948L, 949L, 950L, 951L, 952L, 953L, 954L, 955L, 956L, 957L, 958L,
959L, 960L, 961L, 962L, 963L, 964L, 965L, 966L, 967L, 968L, 969L,
970L, 971L, 972L, 973L, 974L, 975L, 976L, 977L, 978L, 979L, 980L,
981L, 982L, 983L, 984L, 985L, 986L, 987L, 988L, 989L, 990L, 991L,
992L, 993L, 994L, 995L, 996L, 997L, 998L, 999L, 1000L, 1001L,
1002L, 1003L, 1004L, 1005L, 1006L, 1007L, 1008L, 1009L, 1010L,
1011L, 1012L, 1013L, 1014L, 1015L, 1016L, 1017L, 1018L, 1019L,
1020L, 1021L, 1022L, 1023L, 1024L, 1025L, 1026L, 1027L, 1028L,
1029L, 1030L, 1031L, 1032L, 1033L, 1034L, 1035L, 1036L, 1037L,
1038L, 1039L, 1040L, 1041L, 1042L, 1043L, 1044L, 1045L, 1046L,
1047L, 1048L, 1049L, 1050L, 1201L, 1202L, 1203L, 1204L, 1205L,
1206L, 1207L, 1208L, 1209L, 1210L, 1211L, 1212L, 1213L, 1214L,
1215L, 1216L, 1217L, 1218L, 1219L, 1220L, 1221L, 1222L, 1223L,
1224L, 1225L, 1226L, 1227L, 1228L, 1229L, 1230L, 1231L, 1232L,
1233L, 1234L, 1235L, 1236L, 1237L, 1238L, 1239L, 1240L, 1241L,
1242L, 1243L, 1244L, 1245L, 1246L, 1247L, 1248L, 1249L, 1250L,
1251L, 1252L, 1253L, 1254L, 1255L, 1256L, 1257L, 1258L, 1259L,
1260L, 1261L, 1262L, 1263L, 1264L, 1265L, 1266L, 1267L, 1268L,
1269L, 1270L, 1271L, 1272L, 1273L, 1274L, 1275L, 1276L, 1277L,
1278L, 1279L, 1280L, 1281L, 1282L, 1283L, 1284L, 1285L, 1286L,
1287L, 1288L, 1289L, 1290L, 1291L, 1292L, 1293L, 1294L, 1295L,
1296L, 1297L, 1298L, 1299L, 1300L, 1301L, 1302L, 1303L, 1304L,
1305L, 1306L, 1307L, 1308L, 1309L, 1310L, 1311L, 1312L, 1313L,
1314L, 1315L, 1316L, 1317L, 1318L, 1319L, 1320L, 1321L, 1322L,
1323L, 1324L, 1325L, 1326L, 1327L, 1328L, 1329L, 1330L, 1331L,
1332L, 1333L, 1334L, 1335L, 1336L, 1337L, 1338L, 1339L, 1340L,
1341L, 1342L, 1343L, 1344L, 1345L, 1346L, 1347L, 1348L, 1349L,
1350L, 1501L, 1502L, 1503L, 1504L, 1505L, 1506L, 1507L, 1508L,
1509L, 1510L, 1511L, 1512L, 1513L, 1514L, 1515L, 1516L, 1517L,
1518L, 1519L, 1520L, 1521L, 1522L, 1523L, 1524L, 1525L, 1526L,
1527L, 1528L, 1529L, 1530L, 1531L, 1532L, 1533L, 1534L, 1535L,
1536L, 1537L, 1538L, 1539L, 1540L, 1541L, 1542L, 1543L, 1544L,
1545L, 1546L, 1547L, 1548L, 1549L, 1550L, 1551L, 1552L, 1553L,
1554L, 1555L, 1556L, 1557L, 1558L, 1559L, 1560L, 1561L, 1562L,
1563L, 1564L, 1565L, 1566L, 1567L, 1568L, 1569L, 1570L, 1571L,
1572L, 1573L, 1574L, 1575L, 1576L, 1577L, 1578L, 1579L, 1580L,
1581L, 1582L, 1583L, 1584L, 1585L, 1586L, 1587L, 1588L, 1589L,
1590L, 1591L, 1592L, 1593L, 1594L, 1595L, 1596L, 1597L, 1598L,
1599L, 1600L, 1601L, 1602L, 1603L, 1604L, 1605L, 1606L, 1607L,
1608L, 1609L, 1610L, 1611L, 1612L, 1613L, 1614L, 1615L, 1616L,
1617L, 1618L, 1619L, 1620L, 1621L, 1622L, 1623L, 1624L, 1625L,
1626L, 1627L, 1628L, 1629L, 1630L, 1631L, 1632L, 1633L, 1634L,
1635L, 1636L, 1637L, 1638L, 1639L, 1640L, 1641L, 1642L, 1643L,
1644L, 1645L, 1646L, 1647L, 1648L, 1649L, 1650L, 1801L, 1802L,
1803L, 1804L, 1805L, 1806L, 1807L, 1808L, 1809L, 1810L, 1811L,
1812L, 1813L, 1814L, 1815L, 1816L, 1817L, 1818L, 1819L, 1820L,
1821L, 1822L, 1823L, 1824L, 1825L, 1826L, 1827L, 1828L, 1829L,
1830L, 1831L, 1832L, 1833L, 1834L, 1835L, 1836L, 1837L, 1838L,
1839L, 1840L, 1841L, 1842L, 1843L, 1844L, 1845L, 1846L, 1847L,
1848L, 1849L, 1850L, 1851L, 1852L, 1853L, 1854L, 1855L, 1856L,
1857L, 1858L, 1859L, 1860L, 1861L, 1862L, 1863L, 1864L, 1865L,
1866L, 1867L, 1868L, 1869L, 1870L, 1871L, 1872L, 1873L, 1874L,
1875L, 1876L, 1877L, 1878L, 1879L, 1880L, 1881L, 1882L, 1883L,
1884L, 1885L, 1886L, 1887L, 1888L, 1889L, 1890L, 1891L, 1892L,
1893L, 1894L, 1895L, 1896L, 1897L, 1898L, 1899L, 1900L, 1901L,
1902L, 1903L, 1904L, 1905L, 1906L, 1907L, 1908L, 1909L, 1910L,
1911L, 1912L, 1913L, 1914L, 1915L, 1916L, 1917L, 1918L, 1919L,
1920L, 1921L, 1922L, 1923L, 1924L, 1925L, 1926L, 1927L, 1928L,
1929L, 1930L, 1931L, 1932L, 1933L, 1934L, 1935L, 1936L, 1937L,
1938L, 1939L, 1940L, 1941L, 1942L, 1943L, 1944L, 1945L, 1946L,
1947L, 1948L, 1949L, 1950L, 2101L, 2102L, 2103L, 2104L, 2105L,
2106L, 2107L, 2108L, 2109L, 2110L, 2111L, 2112L, 2113L, 2114L,
2115L, 2116L, 2117L, 2118L, 2119L, 2120L, 2121L, 2122L, 2123L,
2124L, 2125L, 2126L, 2127L, 2128L, 2129L, 2130L, 2131L, 2132L,
2133L, 2134L, 2135L, 2136L, 2137L, 2138L, 2139L, 2140L, 2141L,
2142L, 2143L, 2144L, 2145L, 2146L, 2147L, 2148L, 2149L, 2150L,
2151L, 2152L, 2153L, 2154L, 2155L, 2156L, 2157L, 2158L, 2159L,
2160L, 2161L, 2162L, 2163L, 2164L, 2165L, 2166L, 2167L, 2168L,
2169L, 2170L, 2171L, 2172L, 2173L, 2174L, 2175L, 2176L, 2177L,
2178L, 2179L, 2180L, 2181L, 2182L, 2183L, 2184L, 2185L, 2186L,
2187L, 2188L, 2189L, 2190L, 2191L, 2192L, 2193L, 2194L, 2195L,
2196L, 2197L, 2198L, 2199L, 2200L, 2201L, 2202L, 2203L, 2204L,
2205L, 2206L, 2207L, 2208L, 2209L, 2210L, 2211L, 2212L, 2213L,
2214L, 2215L, 2216L, 2217L, 2218L, 2219L, 2220L, 2221L, 2222L,
2223L, 2224L, 2225L, 2226L, 2227L, 2228L, 2229L, 2230L, 2231L,
2232L, 2233L, 2234L, 2235L, 2236L, 2237L, 2238L, 2239L, 2240L,
2241L, 2242L, 2243L, 2244L, 2245L, 2246L, 2247L, 2248L, 2249L,
2250L), class = "data.frame")
using the vector:
timevec1 = as.vector(ggplot2:::breaks(sumsq$diffdist, "n", n=8))
I normally summarise the data using xtabs and cutusing:
bb1 = data.frame(xtabs(~ratperc +cut(diffdist, timevec1 ), dat=sumsq))
colnames(bb1) = c("rating", "range", "freq", "id")
While this solution is not idea for what I wanted it, I was able to then summarise the values for each cut using ddply.
However now I need to preserve the part_no too, but I can't seem to be able to pass more than one column to cut.
The question is, is there any way to do everything in one step? Basically get for each participant the mean of all the ratings for each cut? In other words, part_no as rows, ranges as columns and the intersection being the mean of ratings for the values that below there.
If you just want the mean rating for each part_no and interval from cut(diffdist, timevec1 ) I would just do something like this:
#Add cut variable as new column
sumsq$range <- cut(sumsq$diffdist,timevec1)
#Summarise using ddply
ddply(sumsq,.(part_no,range),summarise,val = mean(ratperc))
I didn't get if you want the mean for each participant and interval or the cumulative mean along the intervals for each participant.
If you want the normal mean you can get it with
sapply(split(sumsq, cut(sumsq$diffdist, timevec1)), function(ss)
sapply(split(ss$ratperc, ss$part_no), mean))
If you want the cumulative you can rephrase it as
t(sapply(split(sumsq, sumsq$part_no), function(ss){
sapply(timevec1[-1], function(tc) mean(ss$ratperc[ss$diffdist <= tc]))
}))

Resources