find identical values in different numerics (or columns of a dataframe) - r

I have two numerics of different length and I need to find a value in the 2nd numeric that is identical with one of the values in the 1st numeric (currently, only one value is identical, but I do not know which). e.g.:
x <- c(15,43,46,76,111,138,205,227,242,330,333,339,348,380,402,403,498,534,579)
y <- c(391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487,
488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 503, 504, 505, 506, 507)
My solutions so far failed: I was able to construct a dataframe with the numerics as columns.
df <- dataframe(x=x,y=y)
But:
With which(df$y==15) I can only compare one value at once.
With dplyr::duplicate() I can only find identical values within one column or within the same row.
Currently, I work with just two columns. But it would also be helpful to have code when there are three columns and the goal is to find a value from column 1 in column 2 and 3.
Has anyone an idea?

You can find identical values using intersect for multiple vectors like this:
Reduce(intersect, list(y,x))
Output:
[1] 498

You can use the %in% operator to ask which elements of y are in x e.g.
which(y %in% x)
#> [1] 105
that gives the index of the element(s) in y that are also in x. You can subset with that to find the actual vales:
y[which(y %in% x)]
#> [1] 498
You can then combine %in% operations with & if you have more than one vector you want to check.
z <- 498
y[which(y %in% x & y %in% z)]
#> [1] 498
You'll get back an empty vector if there's no matches.
z <- 500
y[which(y %in% x & y %in% z)]
#> numeric(0)

Related

Autopltoing a dataset that has been converted to TS

I have a dataset named "BEDATA_grouped" that I am trying to autoplot. However, whenever I attempt to convert into a time series and use the autoplot function, I get the following error:
Error in `ggplot2::autoplot()`:
! Objects of type tbl_df/tbl/data.frame not supported by autoplot.
Run `rlang::last_error()` to see where the error occurred.
To convert it to a time series I did the following :
BEDATA_GROUPED %>% mutate(occurrence_yrmn = yearmonth(occurrence_yrmn)) %>% as_tsibble(index = occurrence_yrmn)
Weirdly enough, when I use the following, I am able to use the autoplot function:
BEDATA_GROUPEDts <- ts(BEDATA_GROUPED[,2], frequency = 12, start = c(2014, 1))
I'm wondering why one allows me to autoplot whilst the other does not. The first way is referenced in https://otexts.com/fpp3/tsibbles.html#:~:text=This%20can%20be%20converted%20to%20a%20tsibble%20object%20using%20the%20following%20code%3A.
Dataset:
structure(list(occurrence_yrmn = c("2014-January", "2014-February",
"2014-March", "2014-April", "2014-May", "2014-June", "2014-July",
"2014-August", "2014-September", "2014-October", "2014-November",
"2014-December", "2015-January", "2015-February", "2015-March",
"2015-April", "2015-May", "2015-June", "2015-July", "2015-August",
"2015-September", "2015-October", "2015-November", "2015-December",
"2016-January", "2016-February", "2016-March", "2016-April",
"2016-May", "2016-June", "2016-July", "2016-August", "2016-September",
"2016-October", "2016-November", "2016-December", "2017-January",
"2017-February", "2017-March", "2017-April", "2017-May", "2017-June",
"2017-July", "2017-August", "2017-September", "2017-October",
"2017-November", "2017-December", "2018-January", "2018-February",
"2018-March", "2018-April", "2018-May", "2018-June", "2018-July",
"2018-August", "2018-September", "2018-October", "2018-November",
"2018-December", "2019-January", "2019-February", "2019-March",
"2019-April", "2019-May", "2019-June", "2019-July", "2019-August",
"2019-September", "2019-October", "2019-November", "2019-December",
"2020-January", "2020-February", "2020-March", "2020-April",
"2020-May", "2020-June", "2020-July", "2020-August", "2020-September",
"2020-October", "2020-November", "2020-December", "2021-January",
"2021-February", "2021-March", "2021-April", "2021-May", "2021-June",
"2021-July", "2021-August", "2021-September", "2021-October",
"2021-November", "2021-December"), MCI = c(586, 482, 567, 626,
625, 610, 576, 634, 636, 663, 657, 556, 513, 415, 510, 542, 549,
618, 623, 666, 641, 632, 593, 617, 541, 523, 504, 536, 498, 552,
522, 519, 496, 541, 602, 570, 571, 492, 560, 525, 507, 523, 593,
623, 578, 657, 683, 588, 664, 582, 619, 512, 630, 644, 563, 654,
635, 732, 639, 748, 719, 567, 607, 746, 739, 686, 805, 762, 696,
777, 755, 675, 704, 617, 732, 609, 464, 487, 565, 609, 513, 533,
505, 578, 526, 418, 428, 421, 502, 452, 509, 492, 478, 469, 457,
457)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-96L))
You have created a tsibble. The autoplot for tsibbles is in feasts. Just add library(feasts) before you do autoplot. I see you are using the wonderful Forecasting: Principles and Practice. You'll get all the packages you need using library(fpp3).
You'll need to assign your BEDATA_GROUPED %>% ... pipe to a variable too: BEDATA_GROUPED <- BEDATA_GROUPED %>% ....
library(tsibble)
library(feasts)
library(dplyr)
df <- df |> mutate(occurrence_yrmn = yearmonth(occurrence_yrmn)) |> as_tsibble(index = occurrence_yrmn)
autoplot(df)
Hope this helps :-)

R geom_forescast use case interpretation

Since I just started getting familiar with forecasting, so I stumbled upon the example here based on which I have a few questions:
How can I forecast for the next 5 years?
What are the red and blue shaded areas around the forecast lines and what's the interpretation?
Why is there a break between the forecast lines and the historical lines?
What forecasting model does geom_forecast use?
lungDeaths data:
structure(c(2134, 1863, 1877, 1877, 1492, 1249, 1280, 1131, 1209,
1492, 1621, 1846, 2103, 2137, 2153, 1833, 1403, 1288, 1186, 1133,
1053, 1347, 1545, 2066, 2020, 2750, 2283, 1479, 1189, 1160, 1113,
970, 999, 1208, 1467, 2059, 2240, 1634, 1722, 1801, 1246, 1162,
1087, 1013, 959, 1179, 1229, 1655, 2019, 2284, 1942, 1423, 1340,
1187, 1098, 1004, 970, 1140, 1110, 1812, 2263, 1820, 1846, 1531,
1215, 1075, 1056, 975, 940, 1081, 1294, 1341, 901, 689, 827,
677, 522, 406, 441, 393, 387, 582, 578, 666, 830, 752, 785, 664,
467, 438, 421, 412, 343, 440, 531, 771, 767, 1141, 896, 532,
447, 420, 376, 330, 357, 445, 546, 764, 862, 660, 663, 643, 502,
392, 411, 348, 387, 385, 411, 638, 796, 853, 737, 546, 530, 446,
431, 362, 387, 430, 425, 679, 821, 785, 727, 612, 478, 429, 405,
379, 393, 411, 487, 574), .Dim = c(72L, 2L), .Dimnames = list(
NULL, c("mdeaths", "fdeaths")), .Tsp = c(1974, 1979.91666666667,
12), class = c("mts", "ts", "matrix"))
Code:
library(forecast)
# Data
lungDeaths = cbind(mdeaths, fdeaths)
# Plot
autoplot(lungDeaths) + geom_forecast()
Output:
To remove the gap you can use showgap:
If showgap=FALSE, the gap between the historical observations and the
forecasts is removed.
Code:
library(forecast)
autoplot(lungDeaths) +
geom_forecast(showgap = FALSE)
Output:
To forecast 5 years you can use h to set the number of forecasts:
autoplot(lungDeaths) +
geom_forecast(h = 60, showgap = FALSE)
Output:
To remove the confidence intervals use PI:
If FALSE, confidence intervals will not be plotted, giving only the
forecast line.
library(forecast)
autoplot(lungDeaths) +
geom_forecast(h = 60, showgap = FALSE, PI = FALSE)
Output:

Google OR-Tools Pickup Delivery on graph structure

Being new to OR-Tools libraries I am unable to modify the existing code for my requirements. I'm trying to solve a routing problem based on a graph structure. Right now the distance matrix is configured in a way that each node/location always has a connection to every other node/location. Is it possible to change the distance matrix in a way (sth. link enter -1) to show google or-tools that there are node/locations which don't have connections to certain other nodes?
"""Simple Pickup Delivery Problem (PDP)."""
from ortools.constraint_solver import routing_enums_pb2
from ortools.constraint_solver import pywrapcp
def create_data_model():
"""Stores the data for the problem."""
data = {}
data['distance_matrix'] = [
[
0, 548, 776, 696, 582, 274, 502, 194, 308, 194, 536, 502, 388, 354,
468, 776, 662
],
[
548, 0, 684, 308, 194, 502, 730, 354, 696, 742, 1084, 594, 480, 674,
1016, 868, 1210
],
[
776, 684, 0, 992, 878, 502, 274, 810, 468, 742, 400, 1278, 1164,
1130, 788, 1552, 754
],
[
696, 308, 992, 0, 114, 650, 878, 502, 844, 890, 1232, 514, 628, 822,
1164, 560, 1358
],
[
582, 194, 878, 114, 0, 536, 764, 388, 730, 776, 1118, 400, 514, 708,
1050, 674, 1244
],
[
274, 502, 502, 650, 536, 0, 228, 308, 194, 240, 582, 776, 662, 628,
514, 1050, 708
],
[
502, 730, 274, 878, 764, 228, 0, 536, 194, 468, 354, 1004, 890, 856,
514, 1278, 480
],
[
194, 354, 810, 502, 388, 308, 536, 0, 342, 388, 730, 468, 354, 320,
662, 742, 856
],
[
308, 696, 468, 844, 730, 194, 194, 342, 0, 274, 388, 810, 696, 662,
320, 1084, 514
],
[
194, 742, 742, 890, 776, 240, 468, 388, 274, 0, 342, 536, 422, 388,
274, 810, 468
],
[
536, 1084, 400, 1232, 1118, 582, 354, 730, 388, 342, 0, 878, 764,
730, 388, 1152, 354
],
[
502, 594, 1278, 514, 400, 776, 1004, 468, 810, 536, 878, 0, 114,
308, 650, 274, 844
],
[
388, 480, 1164, 628, 514, 662, 890, 354, 696, 422, 764, 114, 0, 194,
536, 388, 730
],
[
354, 674, 1130, 822, 708, 628, 856, 320, 662, 388, 730, 308, 194, 0,
342, 422, 536
],
[
468, 1016, 788, 1164, 1050, 514, 514, 662, 320, 274, 388, 650, 536,
342, 0, 764, 194
],
[
776, 868, 1552, 560, 674, 1050, 1278, 742, 1084, 810, 1152, 274,
388, 422, 764, 0, 798
],
[
662, 1210, 754, 1358, 1244, 708, 480, 856, 514, 468, 354, 844, 730,
536, 194, 798, 0
],
]
data['pickups_deliveries'] = [
[1, 6],
[2, 10],
[4, 3],
[5, 9],
[7, 8],
[15, 11],
[13, 12],
[16, 14],
]
data['num_vehicles'] = 4
data['depot'] = 0
return data
def print_solution(data, manager, routing, solution):
"""Prints solution on console."""
print(f'Objective: {solution.ObjectiveValue()}')
total_distance = 0
for vehicle_id in range(data['num_vehicles']):
index = routing.Start(vehicle_id)
plan_output = 'Route for vehicle {}:\n'.format(vehicle_id)
route_distance = 0
while not routing.IsEnd(index):
plan_output += ' {} -> '.format(manager.IndexToNode(index))
previous_index = index
index = solution.Value(routing.NextVar(index))
route_distance += routing.GetArcCostForVehicle(
previous_index, index, vehicle_id)
plan_output += '{}\n'.format(manager.IndexToNode(index))
plan_output += 'Distance of the route: {}m\n'.format(route_distance)
print(plan_output)
total_distance += route_distance
print('Total Distance of all routes: {}m'.format(total_distance))
def main():
"""Entry point of the program."""
# Instantiate the data problem.
data = create_data_model()
# Create the routing index manager.
manager = pywrapcp.RoutingIndexManager(len(data['distance_matrix']),
data['num_vehicles'], data['depot'])
# Create Routing Model.
routing = pywrapcp.RoutingModel(manager)
# Define cost of each arc.
def distance_callback(from_index, to_index):
"""Returns the manhattan distance between the two nodes."""
# Convert from routing variable Index to distance matrix NodeIndex.
from_node = manager.IndexToNode(from_index)
to_node = manager.IndexToNode(to_index)
return data['distance_matrix'][from_node][to_node]
transit_callback_index = routing.RegisterTransitCallback(distance_callback)
routing.SetArcCostEvaluatorOfAllVehicles(transit_callback_index)
# Add Distance constraint.
dimension_name = 'Distance'
routing.AddDimension(
transit_callback_index,
0, # no slack
3000, # vehicle maximum travel distance
True, # start cumul to zero
dimension_name)
distance_dimension = routing.GetDimensionOrDie(dimension_name)
distance_dimension.SetGlobalSpanCostCoefficient(100)
# Define Transportation Requests.
for request in data['pickups_deliveries']:
pickup_index = manager.NodeToIndex(request[0])
delivery_index = manager.NodeToIndex(request[1])
routing.AddPickupAndDelivery(pickup_index, delivery_index)
routing.solver().Add(
routing.VehicleVar(pickup_index) == routing.VehicleVar(
delivery_index))
routing.solver().Add(
distance_dimension.CumulVar(pickup_index) <=
distance_dimension.CumulVar(delivery_index))
# Setting first solution heuristic.
search_parameters = pywrapcp.DefaultRoutingSearchParameters()
search_parameters.first_solution_strategy = (
routing_enums_pb2.FirstSolutionStrategy.PARALLEL_CHEAPEST_INSERTION)
# Solve the problem.
solution = routing.SolveWithParameters(search_parameters)
# Print solution on console.
if solution:
print_solution(data, manager, routing, solution)
if __name__ == '__main__':
main()

Trying to replicate an IR signal from a remote with a unknown protocol on ESP8266 using Arduino

I have some problems with resending IR signals from a remote to control my shutters.
I recorded the raw IR codes, but even another Arduino does not recieve anything. It does not print any data.
I am a bit confused about the library ESP8266irRemote. It needs a frequency for sending raw ir data. As the timings are given in ms, I do not understand what this frequncy is supposed to be. Where could I read this frequency from? What are some default values? -- EDIT cleared up, it is the carrier frequency. Seems like the default of 38kHz should be right.
And why could it be that my Arduino does not recieve anything? If I simply use an example for a Samsung TV, it receives everything fine.
Thanks for any help!
EDIT:
uint16_t up3[95] = {444, 1190, 442, 1190, 1256, 376, 1258, 374, 440, 1190, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 1282, 350, 440, 1192, 440, 1192, 440, 1190, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 438, 1194, 1256, 374, 1258, 374, 1256, 19240, 440, 1192, 440, 1192, 1282, 350, 1256, 376, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 1256, 374, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 438, 1192, 440, 1192, 438, 1192, 440, 1192, 440, 1192, 464, 1168, 1256, 376, 1256, 376, 1256}; // UNKNOWN 87FDCA19
uint16_t stop3[95] = {1288, 346, 448, 1182, 1214, 418, 1222, 410, 444, 1188, 438, 1194, 466, 1164, 448, 1184, 440, 1192, 438, 1192, 1258, 374, 380, 1252, 448, 1182, 466, 1166, 448, 1184, 466, 1166, 448, 1182, 404, 1228, 468, 1164, 378, 1252, 1280, 350, 1256, 376, 448, 1184, 1264, 19234, 1220, 414, 402, 1230, 1284, 348, 1252, 380, 406, 1226, 378, 1252, 404, 1228, 404, 1228, 404, 1228, 438, 1192, 1266, 366, 468, 1164, 406, 1226, 446, 1186, 448, 1184, 448, 1184, 378, 1252, 448, 1184, 400, 1232, 448, 1184, 1264, 368, 1254, 376, 468, 1164, 1264}; // UNKNOWN 6CE4F608
uint16_t dwn3[95] = {398, 1252, 1280, 352, 1284, 348, 1250, 380, 446, 1188, 462, 1170, 432, 1198, 378, 1254, 446, 1186, 442, 1188, 1282, 348, 402, 1230, 464, 1166, 434, 1196, 446, 1186, 446, 1186, 434, 1198, 462, 1168, 446, 1186, 446, 1186, 378, 1252, 400, 1230, 1218, 414, 378, 20118, 466, 1168, 1216, 414, 1262, 370, 1194, 436, 398, 1232, 398, 1232, 380, 1252, 464, 1168, 464, 1166, 466, 1164, 1196, 436, 400, 1232, 444, 1188, 400, 1230, 446, 1188, 466, 1164, 378, 1254, 446, 1186, 444, 1186, 466, 1166, 402, 1230, 458, 1172, 1282, 348, 464}; // UNKNOWN 2744EDAC
uint16_t up2[95] = {466, 1186, 444, 1186, 1262, 370, 444, 1186, 1260, 370, 446, 1186, 444, 1186, 446, 1186, 468, 1162, 446, 1186, 1262, 370, 444, 1188, 444, 1186, 444, 1188, 444, 1188, 444, 1186, 446, 1186, 444, 1188, 444, 1186, 444, 1188, 1262, 368, 1262, 370, 444, 1186, 1262, 19236, 446, 1186, 446, 1186, 1260, 370, 444, 1188, 1262, 370, 444, 1186, 446, 1186, 446, 1186, 446, 1186, 444, 1186, 1262, 370, 446, 1186, 444, 1188, 444, 1188, 446, 1186, 446, 1184, 446, 1186, 446, 1186, 446, 1186, 446, 1184, 1262, 370, 1260, 372, 446, 1186, 1260}; // UNKNOWN 2D1A9455
uint16_t stop2[95] = {1260, 374, 442, 1190, 1256, 376, 440, 1190, 1258, 374, 440, 1190, 440, 1192, 442, 1190, 440, 1192, 440, 1192, 1256, 374, 440, 1190, 440, 1192, 440, 1190, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 1256, 374, 1258, 374, 1256, 19240, 1258, 374, 440, 1192, 1256, 374, 440, 1192, 1256, 374, 440, 1192, 440, 1192, 440, 1190, 440, 1190, 440, 1192, 1256, 374, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1192, 440, 1190, 440, 1192, 440, 1192, 440, 1190, 440, 1192, 1256, 374, 1256, 376, 1256}; // UNKNOWN B54FF968
uint16_t dwn2[95] = {478, 1156, 1288, 342, 1288, 344, 450, 1182, 1288, 342, 450, 1182, 476, 1154, 452, 1180, 450, 1180, 450, 1182, 1290, 342, 450, 1182, 476, 1156, 478, 1154, 478, 1154, 474, 1158, 450, 1182, 450, 1182, 474, 1156, 450, 1180, 1292, 340, 476, 1156, 474, 1158, 450, 20048, 476, 1156, 1290, 340, 1266, 366, 450, 1182, 1266, 364, 450, 1182, 476, 1156, 476, 1156, 450, 1182, 474, 1156, 1266, 366, 450, 1182, 474, 1156, 476, 1156, 476, 1156, 474, 1156, 450, 1182, 450, 1182, 474, 1158, 474, 1158, 1266, 366, 450, 1180, 450, 1182, 450}; // UNKNOWN 983238A8
IRsend irsend(4);
void setup() {
// put your setup code here, to run once:
irsend.begin();
}
void loop() {
// put your main code here, to run repeatedly:
irsend.sendRaw(dwn3, 95, 999);
delay(10000);
}
That's the code I used. I recoded the raw arrays using the raw dump example provided with the esp8266ir library.
I cut the import part, but be assured, the correct headers were imported. The code compiles without any issue.
Thanks for the suggested edit. I am sorry about the first, not well organized question.
As you did not provide any code and not much information in general I can only guess.
Possible issues:
wrong emitter wavelength
wrong carrier frequency, typically between 30 and 60kHz. 38kHz is most common.
or some error in sending what you have recorded.
I suggest you first find out how a IR remote control works befor you attempt to build one yourself.

How can I check and add missing rows in a data frame based on an index vector?

I need to add missing rows from "count" based on the "numberclass" that is missing. "numberclass" is the column of the "count" dataset that should go from 1 to 652, but misses some numbers and ends at 645.
To achieve that, I made an index vector that goes from 1 to 652 called c1.
How can I use rbind to add the missing rows that are missing in "count"?
Those missing rows should contain the appropriate number in "numberclass" that is missing and a 0 on the column "sum" in the "count" data frame.
visual example
count
numberclass sum
1 1 3.45
2 2 32.45
3 3 23.11
4 5 21.33
5 6 1.54
c1
V1
1 1
2 2
3 3
4 4
5 5
6 6
finalcount
numberclass sum
1 1 3.45
2 2 32.45
3 3 23.11
4 4 0
5 5 21.33
6 6 1.54
dput(c1)
1:652
> dput(count)
structure(list(numberclass = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156,
157, 158, 159, 160, 161, 162, 163, 164, 166, 167, 168, 169, 170,
171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222,
223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248,
249, 251, 252, 253, 255, 256, 257, 258, 259, 260, 261, 262, 263,
264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289,
290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302,
303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328,
329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341,
342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
355, 356, 357, 358, 360, 361, 362, 363, 364, 365, 366, 367, 368,
369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381,
382, 383, 384, 385, 386, 387, 388, 389, 391, 392, 393, 394, 395,
396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408,
409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421,
422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434,
435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447,
448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460,
461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473,
474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486,
487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499,
500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512,
513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525,
526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538,
539, 540, 541, 542, 543, 545, 546, 547, 548, 549, 550, 551, 552,
554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566,
567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579,
580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592,
593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605,
606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618,
619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631,
632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644,
645, 646, 647, 648, 649, 650, 651, 652), sum = c(237.750666386555,
189.540342857143, 351.867604761905, 195.005685714286, 308.574686424686,
18.2691666666667, 85.6063492063492, 330.872041913642, 12.5832666666667,
81.3559523809524, 940.085002447968, 38.9222222222222, 67.6095238095238,
52.4340924675325, 48.9761904761905, 190.221922510823, 67.2384948051948,
106.311044372294, 50.4888222222222, 40.4883365079365, 146.992341452991,
43.6190142857143, 133.421034293119, 234.662733903319, 41.3940476190476,
27.5869769119769, 4.77619047619048, 1.14404345238095, 33.7083333333333,
44.2833333333333, 22.9526315789474, 21.5833333333333, 10.65,
2.75, 73.0113858363858, 9.41666666666667, 10.9, 30.3830128205128,
58.9269230769231, 1.39285714285714, 267.691666666667, 58.0575757575758,
48.1547008547009, 82.8479908979909, 57.6404761904762, 0.333333333333333,
15.0952380952381, 62.5674603174603, 155.280158730159, 39.9, 82.6307359307359,
24.6282467532468, 301.294040989729, 336.528306349206, 19.0833333333333,
110.152380952381, 151.278584609835, 27.3151515151515, 326.42688974359,
148.124206349206, 250.934674989716, 791.586193783953, 284.357225111163,
26.3166666666667, 689.571152020736, 211.649312496276, 143.23373015873,
104.389479365079, 1977.09488512611, 278.063024283429, 635.353051458803,
255.639689709121, 182.388611918596, 121.218055555556, 53.5880285714286,
29.8071514529915, 289.396377133977, 261.427877777778, 13.0333333333333,
120.082323232323, 26.4499333333333, 118.030555555556, 3.16666666666667,
3.5, 1.27692307692308, 1327.43098544718, 359.099526103064, 886.03077133796,
77.9476163059163, 3.7, 204.405522222222, 42.3193805944056, 83.1319512987013,
32.0430735930736, 100.999933333333, 41.4505205838606, 359.286551817072,
134.815597663857, 120.851665339892, 68.6170634920635, 120.464757456432,
98.7313991341991, 138.937179487179, 18.4913941580642, 8.9984237984238,
238.521621356421, 123.083044733045, 363.372644000444, 39.2380952380952,
3.16666666666667, 19.6226551226551, 53.5838383838384, 34.581746031746,
4.95, 131.300949206349, 445.728384935065, 109.100990092656, 364.408721825397,
61.5416666666667, 222.299498645799, 16.0214285714286, 13.5833333333333,
35.9928238095238, 522.570385291901, 92.072619047619, 451.015331590632,
276.63253968254, 61.6666666666667, 56.875, 246.15873015873, 52.5833,
73.5964119047619, 28.1214646464646, 30.1333333333333, 53.9054945054945,
206.796237085137, 111.121428571429, 182.169199264787, 59.3175971087736,
64.3332722832723, 16.9333333333333, 13.9166666666667, 23.3833333333333,
33.8173992673993, 1.50952380952381, 1.1, 47.9876584126984, 33.6666666666667,
31.7166666666667, 42.5094738594739, 193.209163059163, 36.8706349206349,
56.4786214285714, 125.781411481369, 1326.37051628773, 128.802066528312,
176.118690340834, 124.811656943091, 221.328297720058, 92.4357277483439,
5.54453781512605, 11.934710550887, 34.1893281555046, 297.559209282097,
10.45, 15.9714285714286, 0.333333333333333, 404.635647619048,
1.33333333333333, 423.917088383838, 31.725, 22.2334666666667,
126.991549902454, 46.2095071428571, 19.9333333333333, 9.41666666666667,
36.1666666666667, 101.691628950685, 88.0833333333333, 1.08333333333333,
60.5678571428571, 44.5857142857143, 10.3333333333333, 27.9333333333333,
59.6450530463688, 33.0823773448773, 15.2018740031898, 139.796428571429,
302.865200865801, 58.4464285714286, 7.50238095238095, 253.278364368964,
98.456746031746, 275.551738539239, 224.303773488182, 43.4340004939634,
14.475, 252.068551587302, 193.944014285714, 97.1103202020202,
522.762237662338, 152.027922077922, 495.599785289496, 15.45,
44.4584599224305, 2.63932178932179, 76.913480952381, 18.5944333333333,
80.5424963924964, 52.8404761904762, 19.602380952381, 21.7789854538307,
2.09285714285714, 15.6, 57.8281523809524, 114.880233333333, 2.5,
582.268982688364, 22.8928571428571, 43.5, 71.0449134199134, 13.45,
71.4832666666667, 382.793654822955, 57.6023587301587, 17.8666666666667,
134.694036507937, 8.65833333333333, 6.48333333333333, 167.456313131313,
108.970238095238, 38.0944444444444, 41.4536075036075, 644.437984476377,
64.2714285714286, 1630.6914617297, 81.8621387218045, 977.944218315018,
825.631676469739, 76.9720238095238, 161.353968253968, 70.9142857142857,
122.307142857143, 49.1575757575758, 38.9833333333333, 119.23980017316,
9.5, 7, 9.03333333333333, 0.285714285714286, 2.81558441558442,
34.3352130179203, 423.489491888615, 26.7138582972583, 20.2610666666667,
70.2504356560596, 84.3197993439266, 133.202467136288, 452.717995233655,
320.773420116725, 209.525511634406, 641.329055345934, 9.29166666666667,
20.0666666666667, 23.4825757575758, 42.336926961927, 21.5083333333333,
48.472619047619, 5.68452380952381, 3.61666666666667, 2.66666666666667,
22.6410952702853, 2596.19741576659, 3701.15679179432, 458.475674942574,
0.177777777777778, 236.511739558926, 178.846204916721, 554.69148345371,
109.069139904866, 27.9428571428571, 865.353323873349, 1315.57171181985,
4.94494734487734, 367.766031285642, 519.099162156913, 703.569199879477,
570.161782712288, 55.7592247797747, 424.061781409081, 4.14444444444444,
7.85, 1.5, 203.543559424236, 417.414520853467, 118.026934176934,
13.8930333333333, 5.3, 195.214038429218, 2, 125.901590928837,
20.183510972172, 174.23474402697, 115.783354224877, 20.9589971153889,
64.2541744390332, 30.1928142135642, 653.283386817422, 45.4998949579832,
2.28333333333333, 35.7234848484849, 13.4766233766234, 1, 1, 151.923361772117,
466.496416114588, 241.639269088134, 208.697684171547, 37.1753432142857,
32.7720180265813, 28.2666666666667, 32.9353202020202, 29.3107466063348,
52.1338661616162, 92.2408604474645, 143.825094880675, 146.094892496393,
185.56378660516, 229.435060026582, 35.8161587301587, 358.75152088854,
9.54144989396568, 100.579542891096, 48.5654928571429, 182.120363315018,
92.411123015873, 213.978268831169, 30.4477001960784, 133.023283627484,
1.48156826833297, 8.58333333333333, 4.44443333333333, 38.2468253968254,
56.047481038406, 67.3214285714286, 123.833316666667, 72.7440476190476,
4.04166666666667, 15.0999833333333, 66.4499333333333, 200.083454172494,
6.04285714285714, 160.691602741703, 6.19924242424242, 1.33333333333333,
108.082979449584, 106.752280952381, 14.5075757575758, 17.3920634920635,
131.341230952381, 44.2768897435897, 313.758134920635, 2.16666666666667,
16.6477124183007, 4.75, 23.7767065934066, 114.554377815518, 67.8246376228347,
127.12717047619, 8.01590909090909, 62.9999458874459, 24.5385558774559,
25.4267800865801, 64.9809956302521, 26.8670829004329, 144.936510045837,
18.2714285714286, 181.673313930514, 6.37619047619048, 122.4944,
163.107067798868, 62.2391525974026, 100.821861471861, 66.6090659340659,
151.295802741703, 227.115548340548, 161.469246031746, 20.8428571428571,
98.9682406349206, 84.2357142857143, 63.5107142857143, 587.042635340803,
291.116304438862, 217.717193917194, 314.73560018413, 198.123701298701,
236.697900710401, 410.192568542569, 118.817857142857, 143.350727050727,
81.387055999556, 43.8719696969697, 203.429180541681, 517.788687667888,
61.2261904761905, 382.272785934066, 75.7309523809524, 112.349503174603,
22.7539682539683, 31.7878787878788, 71.6388888888889, 116.672591197691,
31.4399816686581, 139.147260092848, 38.9365079365079, 142.327696091318,
73.9474025974026, 353.130164019063, 49.7790027560675, 247.005519209059,
98.4489704073704, 22.8163324675325, 49.0166666666667, 398.237265694185,
20.0119047619048, 127.929437229437, 29.906746031746, 11.4833333333333,
29.5477994227994, 17.2627344877345, 1, 275.39396990232, 155.285052380952,
191.24167394958, 17.5547619047619, 32.6397907647908, 48.0516145404303,
20.0202991341991, 296.087292678082, 6.05553333333333, 6.30952380952381,
550.020158730159, 398.502413950429, 697.700455175612, 342.769086313686,
100.248412698413, 578.569767384318, 323.557284593185, 578.870478870574,
799.803117448702, 66.4497474747475, 52.7964285714286, 28.2440476190476,
1, 9.15, 0.333333333333333, 101.279396149946, 20.4504329004329,
2, 0.342857142857143, 11.0416666666667, 114.264102564103, 148.394093406593,
17.3285625923784, 10.2605680868839, 109.262121733822, 5.68568095238095,
4.91666666666667, 27.8404512154512, 95.3755683538683, 134.882303769841,
61.262513966589, 16.5333333333333, 64.6593323051948, 37.6535103785104,
42.0317820956821, 17.3730092063492, 81.8735937673438, 44.7111111111111,
17.4607142857143, 70.0927904761905, 148.696792063492, 170.374507625708,
185.520274170274, 177.809072871573, 86.3721112221112, 176.200008488178,
15.1166666666667, 136.109471067821, 48.0101062250443, 166.262856565657,
148.329752057299, 151.820306375846, 4.18642884892885, 13.65,
17.5384920634921, 158.262582783883, 255.417342568543, 29.2134920634921,
197.809798534799, 29.85, 16.9095238095238, 20.8333333333333,
113.602744444444, 44.002380952381, 36.0333333333333, 318.15949047619,
116.7, 9.73333333333333, 459.457291197691, 200.920720879121,
314.905574729437, 468.928687626263, 127.85367965368, 34.46829004329,
127.564573784059, 168.830957864358, 276.134640779221, 201.892396392496,
1946.09400347577, 201.03562536075, 0.54047619047619, 782.099165160003,
425.714983516484, 89.7872682539683, 146.385452539683, 10.6666666666667,
1025.68925909923, 116.007914285714, 276.85727701204, 289.008666233766,
251.763574012009, 83.7539682539683, 348.782956092124, 241.232478499278,
35.9951548451548, 23.8844904761905, 16.75, 15.6583166666667,
23.4777777777778, 5.83333333333333, 262.787474045562, 285.537711241699,
63.2683473389356, 66.3647186147186, 2, 8.83323333333333, 751.311316139416,
20.0833333333333, 3.48333333333333, 313.547763557495, 24.6952380952381,
2.33333333333333, 60.6101524475524, 111.872585714286, 52.7153693528694,
181.421808730159, 86.6900043290043, 223.108003141303, 16.0825757575758,
304.663375396825, 48.2595238095238, 53.0539682539683, 117.610714285714,
3.1, 1.83333333333333, 305.834008148714, 197.169349200473, 0.5,
8, 33.7777777777778, 1.2, 5.58333333333333, 42.6051282051282,
144.887301587302, 65.7499666666667, 963.598530853141, 217.737908305747,
19.827380952381, 3.775, 229.018578571429, 7.19166666666667, 186.860334126984,
9.33333333333333, 0.75, 1, 43.8273809523809, 62.2753634920635,
301.048005944774, 89.4083452763611, 374.762004736842, 166.820046453546,
1058.5261360623, 872.182726540127, 54.4082666666667, 1227.53727689429,
321.227890629965, 148.721916971917, 277.273484848485, 897.280942113442,
226.137230929597, 72.7005952380952, 140.310317460317, 317.511606180094,
209.189406410256, 104.605501434676, 437.805596256685, 273.362576312576,
8.47222222222222, 227.129921804748, 0.943686868686869, 67.7638777888778,
20.4856893106893, 99.1611000111, 166.165773015873, 82.3694444444444,
227.211077777778, 72.4857142857143, 461.993158401598, 78.8, 210.535976984127,
428.665560794761, 35.797619047619, 133.786890638528, 20.4904761904762,
577.348705757576, 404.170196392496, 1101.04344335286, 270.924821327561,
196.366666666667, 5.83333333333333, 81.6839466089466, 516.43132186441,
2.33333333333333, 10.9095238095238, 54.1369047619048, 48.2956349206349,
676.496237656507, 137.799728238428, 14.4768149941046, 355.509695218997,
422.28376567026, 213.912283405959, 177.353159198024, 14.0459013125763
)), row.names = c(NA, -645L), class = c("tbl_df", "tbl", "data.frame"
))
I've found a solution with the tidyr package:
library(tidyr)
count <- as.data.frame(count)
count <- count %>% complete(numberclass = full_seq(numberclass, period = 1),fill=list(sum=0))
No need for an extra index vector.

Resources