How to remove NA values in vector in R [duplicate] - r

This question already has answers here:
Remove NA values from a vector
(8 answers)
Closed 8 years ago.
I have a vector which stores over 1000 values. The first 50 values are NAs, how can I get rid of it?
c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, 1.5741, 1.583, 1.605, 1.633, 1.6465, 1.6475, 1.6329,
1.6413, 1.685, 1.692, 1.7087, 1.7055, 1.6985, 1.6807, 1.6745,
1.673, 1.6625, 1.6805, 1.689, 1.667, 1.684, 1.6675, 1.6867, 1.6688,
1.6643, 1.6685, 1.7025, 1.737, 1.7663, 1.742, 1.7535, 1.749,
1.7494, 1.75, 1.711, 1.7145, 1.7205, 1.751, 1.7295, 1.7205, 1.7325,
1.731, 1.7235, 1.712, 1.6967, 1.6872, 1.696, 1.7354, 1.729, 1.712,
1.7208, 1.7115, 1.7035, 1.7032, 1.6947, 1.715, 1.7181, 1.742,
1.7471, 1.7438, 1.7493, 1.7525, 1.773, 1.7695, 1.7735, 1.7895,
1.7905, 1.7945, 1.798, 1.8138, 1.791, 1.7915, 1.802, 1.7812,
1.7925, 1.7873, 1.7952, 1.808, 1.8265, 1.8369, 1.83, 1.8347,
1.826, 1.8079, 1.8165, 1.8104, 1.8333, 1.7864, 1.7878, 1.801,
1.79, 1.7745, 1.7493, 1.7625, 1.7575, 1.739, 1.7615, 1.739, 1.7521,
1.752, 1.7445, 1.7585, 1.7375, 1.7188, 1.709, 1.7092, 1.7154,
1.7273, 1.724, 1.7323, 1.7365, 1.7495, 1.7643, 1.8165, 1.811,
1.7395, 1.7365, 1.749, 1.7485, 1.748, 1.738, 1.743, 1.747, 1.7457,
1.7375, 1.738, 1.7391, 1.7155, 1.6909, 1.6953, 1.6984, 1.6795,
1.6885, 1.672, 1.669, 1.6815, 1.6895, 1.6855, 1.6697, 1.6845,
1.683, 1.6865, 1.6715, 1.6628, 1.6687, 1.6674, 1.6638, 1.682,
1.6825, 1.6953, 1.6915, 1.6955, 1.69, 1.7, 1.7105, 1.704, 1.705,
1.6867, 1.6917, 1.6954, 1.71, 1.702, 1.6985, 1.7185, 1.6898,
1.6725, 1.6725, 1.6515, 1.6305, 1.6355, 1.642, 1.631, 1.6425,
1.6375, 1.6355, 1.634, 1.6285, 1.6358, 1.6069, 1.602, 1.5995,
1.595, 1.582, 1.584, 1.5825, 1.6193, 1.6163, 1.6248, 1.6073,
1.615, 1.6125, 1.5865, 1.5718, 1.5714, 1.575, 1.579, 1.5835,
1.586, 1.5774, 1.5755, 1.5715, 1.557, 1.5345, 1.5115, 1.5208,
1.508, 1.5175, 1.5165, 1.517, 1.5268, 1.5444, 1.5195, 1.518,
1.5135, 1.5658, 1.583, 1.5757, 1.5945, 1.6245, 1.6135, 1.609,
1.5923, 1.586, 1.5915, 1.6032, 1.5893, 1.6125, 1.5965, 1.5972,
1.6142, 1.6085, 1.5995, 1.5907, 1.585, 1.5755, 1.563, 1.5768,
1.5917, 1.607, 1.6273, 1.623, 1.6223, 1.6455, 1.6438, 1.6435,
1.653, 1.6518, 1.647, 1.651, 1.6415, 1.6367, 1.6415, 1.6579,
1.672, 1.6737, 1.669, 1.6615, 1.6715, 1.663, 1.668, 1.6665, 1.662,
1.6495, 1.649, 1.6715, 1.6725, 1.6691, 1.6655, 1.6502, 1.6605,
1.6425, 1.6465, 1.645, 1.6545, 1.644, 1.6231, 1.6245, 1.6243,
1.6256, 1.616, 1.637, 1.6572, 1.652, 1.663, 1.669, 1.6685, 1.6693,
1.667, 1.6633, 1.662, 1.6495, 1.6525, 1.6545, 1.6588, 1.6495,
1.6395, 1.6482, 1.6391, 1.629, 1.637, 1.6462, 1.64, 1.6235, 1.6165,
1.6105, 1.6125, 1.5965, 1.5907, 1.6027, 1.6145, 1.6175, 1.6135,
1.6125, 1.639, 1.629, 1.607, 1.612, 1.6051, 1.6049, 1.603, 1.588,
1.5883, 1.591, 1.5944, 1.5793, 1.577, 1.575, 1.5645, 1.5769,
1.5665, 1.5737, 1.5665, 1.5639, 1.5504, 1.5402, 1.536, 1.5158,
1.5246, 1.5215, 1.5102, 1.5183, 1.5117, 1.4945, 1.4945, 1.5135,
1.495, 1.4772, 1.4832, 1.4793, 1.4785, 1.4589, 1.4965, 1.4865,
1.4872, 1.4835, 1.5037, 1.4815, 1.4745, 1.4815, 1.4835, 1.478,
1.4753, 1.475, 1.4775, 1.477, 1.4707, 1.4661, 1.4684, 1.4626,
1.4558, 1.467, 1.463, 1.4568, 1.453, 1.4478, 1.4275, 1.4035,
1.399, 1.4065, 1.4083, 1.4062, 1.4001, 1.3924, 1.3915, 1.4133,
1.4032, 1.4015, 1.3908, 1.41, 1.4095, 1.4482, 1.483, 1.4862,
1.524, 1.4861, 1.5, 1.4815, 1.4938, 1.5, 1.486, 1.484, 1.451,
1.424, 1.417, 1.4235, 1.409, 1.4164, 1.432, 1.4435, 1.4728, 1.493,
1.4685, 1.47, 1.466, 1.4526, 1.4815, 1.4875, 1.5215, 1.5105,
1.5063, 1.5318, 1.537, 1.5345, 1.5374, 1.538, 1.5362, 1.569,
1.5625, 1.569, 1.5795, 1.5945, 1.589, 1.594, 1.5845, 1.5875,
1.567, 1.5885, 1.5995, 1.597, 1.5795, 1.599, 1.6002, 1.6015,
1.5935, 1.5955, 1.6005, 1.5945, 1.576, 1.5705, 1.5818, 1.596,
1.5625, 1.5575, 1.5665, 1.579, 1.5775, 1.569, 1.5675, 1.554,
1.5605, 1.566, 1.567, 1.5875, 1.5945, 1.598, 1.6092, 1.617, 1.6142,
1.6195, 1.637, 1.6265, 1.6345, 1.635, 1.639, 1.6305, 1.6325,
1.6325, 1.6195, 1.6325, 1.6135, 1.6115, 1.6055, 1.615, 1.5935,
1.573, 1.579, 1.586, 1.585, 1.611, 1.6365, 1.643, 1.6465, 1.656,
1.6545, 1.6555, 1.6545, 1.6595, 1.6575, 1.6615, 1.6587, 1.63,
1.628, 1.633, 1.6365, 1.6285, 1.614, 1.6195, 1.6335, 1.6455,
1.646, 1.643, 1.6475, 1.6355, 1.672, 1.6625, 1.668, 1.665, 1.661,
1.6665, 1.662, 1.6615, 1.6645, 1.654, 1.6335, 1.6375, 1.6305,
1.6265, 1.6425, 1.6315, 1.629, 1.618, 1.6085, 1.596, 1.6105,
1.5965, 1.611, 1.617, 1.6065, 1.6035, 1.6035, 1.578, 1.5925,
1.606, 1.6147, 1.5995, 1.595, 1.6035, 1.606, 1.582, 1.567, 1.5805,
1.5855, 1.5815, 1.5845, 1.5815, 1.5715, 1.5775, 1.5795, 1.5825,
1.6055, 1.6084, 1.6135, 1.616, 1.602, 1.6165, 1.624, 1.624, 1.6145,
1.6255, 1.6378, 1.63, 1.6315, 1.607, 1.5868, 1.5895, 1.5927,
1.5948, 1.6004, 1.626, 1.6195, 1.6225, 1.637, 1.629, 1.6235,
1.628, 1.6375, 1.6605, 1.6568, 1.681, 1.6895, 1.6955, 1.6925,
1.7095, 1.7032, 1.6987, 1.692, 1.704, 1.6976, 1.6965, 1.696,
1.698, 1.7091, 1.707, 1.721, 1.7286, 1.7204, 1.7165, 1.7241,
1.7205, 1.7037, 1.7053, 1.6975, 1.7075, 1.72, 1.7245, 1.7243,
1.7185, 1.7385, 1.7402, 1.712, 1.7057, 1.71, 1.712, 1.6975, 1.7,
1.7115, 1.721, 1.7158, 1.7132, 1.6904, 1.6965, 1.6782, 1.6865,
1.6767, 1.686, 1.679, 1.6868, 1.6665, 1.6645, 1.6738, 1.677,
1.658, 1.6445, 1.623, 1.611, 1.6075, 1.6177, 1.5985, 1.5935,
1.612, 1.6085, 1.5935, 1.6047, 1.6092, 1.608, 1.6187, 1.6325,
1.6443, 1.645, 1.6295, 1.6178, 1.6133, 1.6335, 1.6265, 1.623,
1.6255, 1.6221, 1.6215, 1.601, 1.604, 1.5935, 1.604, 1.6145,
1.6137, 1.6285, 1.6377, 1.647, 1.663, 1.676, 1.673, 1.682, 1.6794,
1.6788, 1.6774, 1.694, 1.6965, 1.6937, 1.6957, 1.691, 1.6842,
1.696, 1.6925, 1.691, 1.6908, 1.6865, 1.7023, 1.706, 1.7095,
1.7145, 1.7032, 1.7005, 1.7027, 1.7082, 1.7118, 1.707, 1.7148,
1.7165, 1.7211, 1.7208, 1.7062, 1.7045, 1.704, 1.7055, 1.6985,
1.706, 1.7125, 1.7163, 1.7078, 1.705, 1.7125, 1.7077, 1.701,
1.6935, 1.6965, 1.7019, 1.7008, 1.7175, 1.735, 1.7365, 1.7371,
1.7398, 1.7399, 1.7397, 1.7333, 1.7308, 1.7398, 1.7366, 1.752,
1.7505, 1.7553, 1.7487, 1.744, 1.7358, 1.7474, 1.7504, 1.7528,
1.748, 1.7441, 1.7273, 1.7444, 1.727, 1.7343, 1.7314, 1.736,
1.763, 1.7658, 1.7603, 1.7534, 1.7517, 1.7438, 1.7255, 1.7219,
1.734, 1.718, 1.7275, 1.7269, 1.7279, 1.7306, 1.7055, 1.7069,
1.709, 1.7037, 1.7088, 1.7198, 1.7184, 1.7155, 1.707, 1.6893,
1.6779, 1.6898, 1.6963, 1.691, 1.68, 1.6961, 1.6979, 1.6885,
1.685, 1.6726, 1.668, 1.6728, 1.6675, 1.6788, 1.6695, 1.6952,
1.6985, 1.7071, 1.7151, 1.7181, 1.7134, 1.708, 1.7188, 1.7135,
1.7088, 1.7124, 1.7202, 1.701, 1.694, 1.6882, 1.6947, 1.6794,
1.6801, 1.6727, 1.6697, 1.657, 1.6501, 1.6461, 1.662, 1.6682,
1.6661, 1.6579, 1.6705, 1.6735, 1.6708, 1.6671, 1.674, 1.6683,
1.6596, 1.6551, 1.6463, 1.6456, 1.6478, 1.6447, 1.6438, 1.6444,
1.6466, 1.6435, 1.6428, 1.6515, 1.6665, 1.6692, 1.6695, 1.6698,
1.6721, 1.6672, 1.65, 1.6443, 1.6354, 1.6319, 1.6299, 1.5986,
1.6009, 1.6006, 1.6035, 1.5972, 1.5758, 1.5849, 1.5825, 1.5915,
1.5946, 1.5965, 1.5826, 1.5685, 1.5745, 1.5741, 1.54, 1.5235,
1.5383, 1.5457, 1.5558, 1.5428, 1.5569, 1.5662, 1.576, 1.5955,
1.5849, 1.5865, 1.576, 1.5795, 1.5888, 1.5743, 1.5814, 1.5792,
1.581, 1.5822, 1.5811, 1.582, 1.5745, 1.5872, 1.5557, 1.5533,
1.5552, 1.5603, 1.5456, 1.5396, 1.5309, 1.5377, 1.5411, 1.5462,
1.5615, 1.5831, 1.5805, 1.5783, 1.577, 1.5602, 1.5537, 1.5426,
1.5486, 1.5562, 1.5419, 1.5435, 1.5493, 1.5374, 1.5467, 1.5376,
1.5528, 1.5508, 1.5449, 1.5488, 1.5443, 1.5551, 1.547, 1.5467,
1.5461, 1.5515, 1.5573, 1.5519, 1.5426, 1.5444, 1.5411, 1.55,
1.5466, 1.5421, 1.5423, 1.5201, 1.5036, 1.5003, 1.5009, 1.5016,
1.4954, 1.497, 1.492, 1.4953, 1.4972, 1.5094, 1.5077, 1.4994,
1.4945, 1.5146, 1.5235, 1.5172, 1.5097, 1.53, 1.5348, 1.528,
1.5453, 1.5454, 1.551, 1.548, 1.5539, 1.5594, 1.5536, 1.5537,
1.5582, 1.5589, 1.5643, 1.5612, 1.5703, 1.5722, 1.5778, 1.5741,
1.5725, 1.571, 1.5777, 1.5773, 1.5728, 1.5728, 1.5691, 1.5718,
1.5714, 1.5738, 1.572, 1.5703, 1.5805, 1.5783, 1.5768, 1.5737,
1.5507, 1.55, 1.5539, 1.559, 1.5535, 1.5575, 1.5539, 1.5341,
1.5354, 1.5295, 1.5327, 1.5282, 1.532, 1.53, 1.5303, 1.5087,
1.5095, 1.5127, 1.5183, 1.5147, 1.5119, 1.5099, 1.5148, 1.5228,
1.52, 1.525, 1.5309, 1.5355, 1.5312, 1.5291, 1.5241, 1.5184,
1.5137, 1.5084, 1.4914, 1.4887, 1.4729, 1.4796, 1.4679, 1.4727,
1.4749, 1.458, 1.4644, 1.465, 1.4601, 1.4329, 1.4028, 1.3926,
1.3855, 1.3904, 1.4145, 1.4053, 1.4136, 1.3926, 1.3882, 1.3865,
1.3973, 1.4125, 1.4061, 1.4015, 1.4128, 1.4087, 1.3997, 1.3773,
1.4107, 1.3685, 1.3723, 1.3854, 1.3835, 1.3763, 1.3811, 1.4055,
1.401, 1.4048, 1.3892, 1.39, 1.3715, 1.3677, 1.3542, 1.3704,
1.3766, 1.3699, 1.365, 1.3811, 1.3734, 1.3823, 1.3902, 1.3753,
1.3746, 1.3697, 1.3711, 1.3646, 1.3701, 1.3906, 1.4135, 1.4433,
1.4466, 1.4414, 1.4368, 1.4597, 1.4404, 1.4482, 1.4362, 1.439,
1.4043, 1.3829, 1.3886, 1.3899, 1.413, 1.4233, 1.406, 1.4074,
1.4188, 1.4074, 1.4198, 1.3973, 1.4029, 1.4044, 1.3974, 1.4106,
1.4007, 1.3991, 1.3924, 1.3921, 1.3845, 1.3877, 1.3942, 1.3846,
1.3884, 1.3891, 1.3841, 1.3782, 1.3817, 1.3833, 1.3816, 1.3935,
1.3988, 1.402, 1.4042, 1.3923, 1.391, 1.3963, 1.3883, 1.3887,
1.3767, 1.3865, 1.3837, 1.393, 1.3849, 1.3863, 1.3792, 1.3807,
1.3805, 1.3967, 1.3915, 1.3928, 1.4048, 1.4067, 1.4073, 1.423,
1.4334, 1.4341, 1.4749, 1.4756, 1.4771, 1.4702, 1.4723, 1.4852,
1.4791, 1.4803, 1.4786, 1.4615, 1.4714, 1.4758, 1.4695, 1.4633,
1.4647, 1.4631, 1.479, 1.475, 1.481, 1.4717, 1.4714, 1.4908,
1.4895, 1.4875, 1.4873, 1.4876, 1.4675, 1.44, 1.4175, 1.4278,
1.4413, 1.4268, 1.4212, 1.423, 1.4299, 1.4393, 1.4363, 1.4301,
1.427, 1.4119, 1.4176, 1.4249, 1.4223, 1.4291, 1.4195, 1.4168,
1.4235, 1.4141, 1.3979, 1.3851, 1.387, 1.3936, 1.4017, 1.4006,
1.4053, 1.4083, 1.4164, 1.4191, 1.4155, 1.4134, 1.4167, 1.4166,
1.4161, 1.4123, 1.4195, 1.4145, 1.4024, 1.4095, 1.4048, 1.4125,
1.4079, 1.4085, 1.4136, 1.4165, 1.4358, 1.4338, 1.4368, 1.4453,
1.4451, 1.4381, 1.4363, 1.4432, 1.4416, 1.448, 1.4442, 1.4485,
1.4499, 1.4418, 1.4426, 1.4318, 1.4355, 1.4434, 1.4402, 1.4402,
1.4333, 1.4313, 1.4319, 1.4313, 1.4347, 1.4403, 1.4565, 1.4375,
1.4403, 1.4432, 1.4383, 1.437, 1.4407, 1.4466, 1.4576, 1.4646,
1.4696, 1.479, 1.4755, 1.4773, 1.4803, 1.4763, 1.4912, 1.4859,
1.4899, 1.4879, 1.4933, 1.4872, 1.4693, 1.4718, 1.4773, 1.4762,
1.4774, 1.4725, 1.4782, 1.4692, 1.4713, 1.4617, 1.443, 1.4533,
1.4513, 1.4516, 1.4513, 1.4471, 1.4528, 1.4614, 1.4697, 1.4759,
1.4758, 1.4789, 1.475, 1.4789, 1.4836, 1.4823, 1.4805, 1.4718,
1.4709, 1.476, 1.4742, 1.4762, 1.4775, 1.4763, 1.4753, 1.4777,
1.4758, 1.4875, 1.4781, 1.4764, 1.4832, 1.4818, 1.4792, 1.4805,
1.4826, 1.4778, 1.4918, 1.4997, 1.5013, 1.5037, 1.5104, 1.5096,
1.5073, 1.5121, 1.5057, 1.5164, 1.518, 1.5219, 1.5295, 1.5288,
1.5213, 1.5336, 1.5336, 1.5328, 1.5273, 1.5266, 1.5213, 1.5183,
1.5168, 1.5249, 1.5336, 1.5368, 1.5341, 1.5368, 1.5262, 1.5347,
1.5415, 1.5387, 1.5405, 1.5414, 1.5414, 1.5483, 1.5453, 1.5323,
1.5275, 1.5265, 1.5318, 1.5293, 1.5301, 1.5345, 1.536, 1.5363,
1.5363, 1.5353, 1.5229, 1.5177, 1.5148, 1.5207, 1.5244, 1.5289,
1.5315, 1.5322, 1.5287, 1.5218, 1.5222, 1.5235, 1.527, 1.5252,
1.5235, 1.528, 1.5278, 1.5233, 1.5246, 1.5217, 1.5226, 1.5184,
1.4922, 1.4865, 1.4917, 1.4885, 1.4863, 1.4897, 1.4877, 1.4784,
1.4809, 1.4808, 1.4774, 1.4728, 1.4736, 1.4779, 1.4813, 1.4843,
1.4829, 1.4845, 1.4784, 1.4753, 1.4767, 1.4834, 1.4856, 1.4935,
1.4882, 1.4893, 1.4817, 1.4959, 1.4874, 1.4783, 1.4777, 1.476,
1.4802, 1.4778, 1.4869, 1.4844, 1.4823, 1.4848, 1.4885, 1.4918,
1.508, 1.5098, 1.5122, 1.5124, 1.5095, 1.5143, 1.5084, 1.514,
1.5149, 1.5134, 1.5132, 1.5102, 1.5217, 1.5243, 1.5253, 1.5258,
1.527, 1.5306, 1.5296, 1.5304, 1.5272, 1.5285, 1.5298, 1.5315,
1.5293, 1.5405, 1.5375, 1.5437, 1.543, 1.5362, 1.535, 1.5234,
1.5227, 1.5234, 1.5203, 1.5103, 1.5073, 1.5132, 1.5165, 1.5132,
1.5168, 1.5164, 1.5078, 1.5059, 1.499, 1.4991, 1.5068, 1.5093,
1.5083, 1.5017, 1.5028, 1.4977, 1.499, 1.5023, 1.5192, 1.5276,
1.5261, 1.5316, 1.5371, 1.5424, 1.5665, 1.5627, 1.5547, 1.5404,
1.5566, 1.5539, 1.5412, 1.5439, 1.5466, 1.5534, 1.5454, 1.5544,
1.5601, 1.5539, 1.5536, 1.5553, 1.5564, 1.5552, 1.5567, 1.5411,
1.5418, 1.5575, 1.5649, 1.5628, 1.5714, 1.5757, 1.5841, 1.5895,
1.594, 1.5895, 1.5925, 1.6113, 1.624, 1.6244, 1.6407, 1.639,
1.6268, 1.6376, 1.6511, 1.6436, 1.6394, 1.6377, 1.6429, 1.6415,
1.6484, 1.6501, 1.6722, 1.6565, 1.6721, 1.6832, 1.6871, 1.6862,
1.6995, 1.6914, 1.694, 1.6896, 1.6831, 1.6697, 1.6758, 1.689,
1.6897, 1.6882, 1.6934, 1.7094, 1.7113, 1.7185, 1.7189, 1.7032,
1.7055, 1.7014, 1.7012, 1.6993, 1.6901, 1.6782, 1.6815, 1.6867,
1.6834, 1.6882, 1.6907, 1.6922, 1.6775, 1.6762, 1.6684, 1.6697,
1.6703, 1.6683, 1.6758, 1.711, 1.711, 1.7197, 1.7169, 1.7241,
1.7233, 1.7339, 1.7286, 1.7257, 1.7162, 1.7023, 1.7112, 1.7124,
1.717, 1.7235, 1.7273, 1.7248, 1.7317, 1.7186, 1.7285, 1.732,
1.7231, 1.7194, 1.7075, 1.6934, 1.7004, 1.6972, 1.7006, 1.6983,
1.6941, 1.7072, 1.6949, 1.695, 1.6933, 1.6907, 1.6911, 1.7012,
1.6968, 1.6967, 1.7056, 1.7262, 1.7261, 1.7294, 1.7289, 1.7289,
1.7085, 1.7167, 1.7148, 1.724, 1.7378, 1.7295, 1.7338, 1.727,
1.7247, 1.7321, 1.7224, 1.724, 1.7235, 1.7286, 1.7363, 1.7426,
1.7401, 1.7511, 1.749, 1.7539, 1.7448, 1.7572, 1.7619, 1.7512,
1.7696, 1.7909, 1.8003, 1.7974, 1.7922, 1.7907, 1.7964, 1.8127,
1.8273, 1.8306, 1.8372, 1.8445, 1.8291, 1.8377, 1.8368, 1.8567,
1.8639, 1.879, 1.8745, 1.8733, 1.8531, 1.8544, 1.8624, 1.8316,
1.8461, 1.8183, 1.8223, 1.8364, 1.8568, 1.842, 1.8173, 1.8202,
1.8005, 1.8104, 1.7964, 1.8002, 1.8114, 1.8328, 1.8184, 1.8182,
1.8068, 1.8103, 1.8111, 1.8015, 1.7915, 1.7699, 1.7632, 1.7681,
1.7686, 1.7708, 1.7713, 1.793, 1.7954, 1.7717, 1.7678, 1.7647,
1.7589, 1.7662, 1.7756, 1.7671, 1.7625, 1.7622, 1.7539, 1.754,
1.739, 1.7499, 1.7506, 1.7564, 1.7511, 1.7443, 1.7687, 1.7714,
1.7851, 1.7815, 1.7747, 1.7783, 1.7599, 1.7248, 1.7416, 1.7231,
1.7211, 1.7362, 1.721, 1.7232, 1.7209, 1.7055, 1.7116, 1.7113,
1.7238, 1.7233, 1.7308, 1.7336, 1.7252, 1.7327, 1.7314, 1.748,
1.7353, 1.7437, 1.7593, 1.7642, 1.7639, 1.7774, 1.7746, 1.7684,
1.7704, 1.7828, 1.7884, 1.7946, 1.783, 1.7733, 1.7732, 1.7702,
1.7846, 1.7718, 1.7725, 1.7688, 1.7804, 1.7733, 1.7724, 1.7724,
1.7836, 1.7915, 1.7981, 1.8037, 1.8185, 1.8226, 1.8257, 1.8166,
1.8203, 1.8185, 1.8213, 1.8228, 1.8312, 1.8271, 1.8367, 1.8408,
1.8273, 1.8025, 1.7805, 1.7891, 1.7891, 1.8054, 1.8233, 1.828,
1.8223, 1.819, 1.8082, 1.7888, 1.7934, 1.8138, 1.8087, 1.8205,
1.8097, 1.8243, 1.8186, 1.8248, 1.8196, 1.8243, 1.8218, 1.7988,
1.8019, 1.8117, 1.8131, 1.8148, 1.8122, 1.8089, 1.8187, 1.829,
1.8322, 1.827, 1.8312, 1.8366, 1.8278, 1.8167, 1.8208, 1.8138,
1.826, 1.8273, 1.8343, 1.8282, 1.8295, 1.8266, 1.8233, 1.8279,
1.8446, 1.8494, 1.8497, 1.849, 1.8473, 1.8427, 1.8388, 1.8244,
1.8176, 1.8176, 1.823, 1.8037, 1.797, 1.8076, 1.8075, 1.8024,
1.7904, 1.7917, 1.7987, 1.7953, 1.7896, 1.7951, 1.7938, 1.7945,
1.7793, 1.7815, 1.7728, 1.7648, 1.7638, 1.7688, 1.7765, 1.7747,
1.7778, 1.7779, 1.7814, 1.7892, 1.7845, 1.77, 1.7575, 1.7574,
1.7672, 1.7721, 1.7816, 1.778, 1.7828, 1.7803, 1.7818, 1.7719,
1.7637, 1.7731, 1.7775, 1.7796, 1.7966, 1.8041, 1.8044, 1.8132,
1.798, 1.79, 1.7899, 1.7829, 1.7944, 1.8009, 1.8015, 1.7955,
1.8098, 1.8133, 1.805, 1.8185, 1.8221, 1.8185, 1.808, 1.8122,
1.8179, 1.8292, 1.8183, 1.8036, 1.7988, 1.803, 1.792, 1.7881,
1.7785, 1.7876, 1.7907, 1.7926, 1.7788, 1.7824, 1.7754, 1.7736,
1.7746, 1.7786, 1.7844, 1.7832, 1.7719, 1.7682, 1.7727, 1.7796,
1.7813, 1.7747, 1.7844, 1.7969, 1.7938, 1.7973, 1.8004, 1.7995,
1.8023, 1.7964, 1.7993, 1.8076, 1.8076, 1.7764, 1.7635, 1.7493,
1.7508, 1.7244, 1.7346, 1.725, 1.7291, 1.7242, 1.692, 1.6878,
1.7031, 1.687, 1.6918, 1.681, 1.6915, 1.6826, 1.6849, 1.6873,
1.6788, 1.6711, 1.6806, 1.678, 1.6714, 1.6502, 1.6366, 1.6348,
1.6389, 1.6134, 1.6084, 1.6339, 1.6493, 1.6374, 1.6445, 1.624,
1.6232, 1.6288, 1.6421, 1.6482, 1.639, 1.6353, 1.6449, 1.6583,
1.6572, 1.6505, 1.6562, 1.6507, 1.6588, 1.6693, 1.6581, 1.6623,
1.6875, 1.684, 1.6783, 1.6927, 1.6892, 1.6668, 1.6694, 1.6676,
1.68, 1.6887, 1.7044, 1.7045, 1.7047, 1.7036, 1.7084, 1.6908,
1.678, 1.673, 1.6741, 1.6755, 1.6764, 1.671, 1.6679, 1.6595,
1.6536, 1.6523, 1.6591, 1.6672, 1.6645, 1.6643, 1.6732, 1.6753,
1.6742, 1.6803, 1.679, 1.6722, 1.672, 1.6656, 1.6576, 1.6598,
1.6688, 1.6759, 1.693, 1.6957, 1.6945, 1.6712, 1.6716, 1.6875,
1.6865, 1.6852, 1.6904, 1.6885, 1.6887, 1.6916, 1.6899, 1.7003,
1.713, 1.7222, 1.7302, 1.7225, 1.7238, 1.7324, 1.7329, 1.7387,
1.7308, 1.7276, 1.7312, 1.7342, 1.7406, 1.7494, 1.7412, 1.7429,
1.7627, 1.7729, 1.7812, 1.7856, 1.7698, 1.7817, 1.7889, 1.7899,
1.7915, 1.8061, 1.8026, 1.7972, 1.7964, 1.7854, 1.8057, 1.7872,
1.7871, 1.793, 1.7768, 1.7803, 1.7902, 1.7936, 1.7948, 1.7909,
1.7989, 1.8221, 1.825, 1.8174, 1.8116, 1.809, 1.8131, 1.8242,
1.8175, 1.8117, 1.8053, 1.8149, 1.8031, 1.8126, 1.8091, 1.8232,
1.827, 1.8429, 1.8354, 1.8439, 1.8458, 1.8373, 1.8447, 1.8367,
1.8394, 1.8467, 1.8487, 1.8508, 1.8437, 1.8316, 1.8146, 1.813,
1.8105, 1.8235, 1.8324, 1.8404, 1.8279, 1.8322, 1.834, 1.8352,
1.8408, 1.8529, 1.8499, 1.8435, 1.8667, 1.8701, 1.8705, 1.8755,
1.869, 1.8882, 1.8892, 1.8981, 1.8995, 1.8759, 1.8752, 1.8646,
1.864, 1.8746, 1.8778, 1.8961, 1.8958, 1.8833, 1.8956, 1.8978,
1.8969, 1.8905, 1.8688, 1.8856, 1.892, 1.8966, 1.9088, 1.9138,
1.9118, 1.9082, 1.913, 1.9214, 1.9195, 1.9291, 1.9214, 1.9162,
1.9089, 1.9141, 1.9224, 1.8788, 1.8626, 1.8642, 1.8686, 1.8353,
1.8405, 1.8428, 1.8254, 1.8275, 1.8344, 1.8341, 1.8172, 1.8108,
1.8141, 1.8279, 1.8225, 1.8349, 1.8373, 1.8508, 1.8506, 1.8615,
1.8561, 1.8405, 1.8369, 1.8487, 1.8586, 1.8707, 1.8758, 1.8708,
1.8721, 1.8517, 1.8462, 1.8263, 1.8446, 1.849, 1.849, 1.8452,
1.8517, 1.8678, 1.8828, 1.8752, 1.8815, 1.8804, 1.88, 1.8788,
1.8671, 1.8622, 1.875, 1.8686, 1.8727, 1.8628, 1.8438, 1.8366,
1.8282, 1.828, 1.8311, 1.8268, 1.8223, 1.8404, 1.8383, 1.823,
1.8174, 1.8141, 1.797, 1.803, 1.8116, 1.8149, 1.8095, 1.8293,
1.8319, 1.8472, 1.8577, 1.8577, 1.8609, 1.8641, 1.8641, 1.8662,
1.8726, 1.8786, 1.886, 1.8799, 1.8744, 1.8796, 1.8954, 1.8977,
1.8975, 1.8819, 1.8958, 1.9003, 1.8938, 1.9002, 1.9182, 1.9184,
1.9333, 1.9433, 1.9424, 1.9406, 1.9491, 1.9532, 1.9126, 1.9124,
1.9088, 1.9217, 1.9244, 1.9334, 1.945, 1.9489, 1.9212, 1.9375,
1.9395, 1.9386, 1.9403, 1.9261, 1.9326, 1.9417, 1.9468, 1.9513,
1.9265, 1.8985, 1.8921, 1.8899, 1.9009, 1.9055, 1.8993, 1.904,
1.9042, 1.932, 1.9397, 1.9349, 1.9367, 1.9373, 1.9423, 1.9514,
1.9433, 1.9535, 1.9789, 1.996, 1.9991, 2.0104, 2.0119, 1.9873,
1.9963, 1.9994, 1.9828, 1.9759, 1.9848, 1.9843, 1.9957, 1.9886,
1.9883, 1.9836, 1.9854, 1.9815, 1.9422, 1.9485, 1.9636, 1.9983,
2.0228, 2.0315, 2.0203, 2.0241, 2.0336, 2.0347, 2.0428, 2.0434,
2.0184, 2.0279, 2.0231, 2.0314, 2.0185, 2.0097, 2.0197, 2.0174,
2.0137, 2.0342, 2.0156, 2.0131, 2.0152, 2.0223, 2.0517, 2.0467,
2.044, 2.0451, 2.0488, 2.0254, 2.0394, 2.0403, 2.038, 2.0313,
2.0419, 2.0469, 2.0456, 2.0482, 2.0605, 2.0795, 2.0818, 2.0818,
2.0815, 2.109, 2.1178, 2.1455, 2.1464, 2.1531, 2.1543, 2.1936,
2.1923, 2.1908, 2.1884, 2.1675, 2.1464, 2.1644, 2.1571, 2.1344,
2.1609, 2.1952, 2.1886, 2.1908, 2.1637, 2.1522, 2.1554, 2.1567,
2.1124, 2.1083, 2.0975, 2.109, 2.1007, 2.0716, 2.0708, 2.0397,
2.0435, 2.0514, 2.0568, 2.0505, 2.036, 2.0396, 2.0532, 2.0357,
2.0368, 2.0472, 2.0672, 2.0819, 2.0886, 2.0873, 2.0734, 2.0677,
2.0534, 2.0404, 2.0554, 2.0591, 2.0448, 2.0465, 2.0605, 2.053,
2.0568, 2.0711, 2.0915, 2.0869, 2.0923, 2.098, 2.1162, 2.1157,
2.0976, 2.0962, 2.078, 2.0758, 2.0825, 2.1097, 2.1108, 2.1132,
2.1403, 2.1627, 2.1526, 2.1532, 2.1738, 2.1789, 2.152, 2.1616,
2.1635, 2.1418, 2.1453, 2.1385, 2.1521, 2.1642, 2.1776, 2.188,
2.1665, 2.1614, 2.1751, 2.182, 2.1892, 2.1999, 2.1733, 2.1739,
2.2071, 2.2274, 2.2455, 2.2574, 2.2695, 2.2724, 2.2623, 2.2706,
2.2662, 2.2892, 2.2913, 2.3078, 2.2932, 2.2183, 2.2398, 2.2223,
2.2194, 2.2152, 2.2164, 2.2184, 2.2318, 2.2409, 2.2495, 2.249,
2.2507, 2.2528, 2.2381, 2.2678, 2.2757, 2.3048, 2.3014, 2.3075,
2.3295, 2.3352, 2.3397, 2.3363, 2.3603, 2.3594, 2.3209, 2.3147,
2.3075, 2.2806, 2.274, 2.2648, 2.2711, 2.2724, 2.2841, 2.2772,
2.2651, 2.274, 2.2794, 2.2758, 2.2894, 2.2938, 2.304, 2.313,
2.3194, 2.3226, 2.3289, 2.304, 2.2877, 2.2741, 2.2468, 2.2405,
2.1992, 2.2101, 2.2111, 2.1982, 2.2024, 2.2279, 2.2298, 2.2339,
2.204, 2.1793, 2.1835, 2.195, 2.1569, 2.1398, 2.118, 2.1057,
2.1018, 2.1128, 2.0833)

And even shorter:
v <- na.omit(v)

Try this:
new.v <- v[ !is.na( v ) ]

Either is.na or na.omit are good enough for this situation
x <- c(1,NA,2,NA, 3) # a vector with NA
x[!is.na(x)] # a vector without NA
[1] 1 2 3
as.numeric(na.omit(x))
[1] 1 2 3
Actually as.numeric applied to na.omit is not necessary as you can tell from Dirk's answer :)

Related

How to visualize a multiple linear regression model?

Does anyone know why this multiple regression model's visualization fails?
This is not a syntax error or typo. I think I missed something, but don't know what's the missing part.
> Oct_Mar %>% model(lm(ctr ~ view + price_view + cart + price_cart +
> purchase + price_purchase)) %>% forecast(new_data(Oct_Mar, 30) %>%
> autoplot(Oct_Mar)
Error throws as below
#MULTIPLE LINEAR REGRESSION MODEL
##############################################################
library(stats)
library(tidyverse)
#Da es sich bei den Daten des ausgewählten Datenset um Panel Data handelt nutze ich das Multiple Regression Model lm_Oct_Mar <- lm(ctr ~ view + price_view + cart + price_cart + purchase + price_purchase, data=Oct_Mar) summary(lm_Oct_Mar)
Fit.consMR <- lm(ctr ~ view + price_view + cart + price_cart + purchase + price_purchase, data=Oct_Mar)
#ctr=1.844e-02 + -7.330e-09*view + 1.010e-07*price_view + 1.639e-088*cart + -2.222e-07*price_cart + 3.302e-07*purchase + -4.157e-07*price_purchase
```
structure(list(date = c("2019.10.01", "2019.10.02", "2019.10.03",
"2019.10.04", "2019.10.05", "2019.10.06", "2019.10.07", "2019.10.08",
"2019.10.09", "2019.10.10", "2019.10.11", "2019.10.12", "2019.10.13",
"2019.10.14", "2019.10.15", "2019.10.16", "2019.10.17", "2019.10.18",
"2019.10.19", "2019.10.20", "2019.10.21", "2019.10.22", "2019.10.23",
"2019.10.24", "2019.10.25", "2019.10.26", "2019.10.27", "2019.10.28",
"2019.10.29", "2019.10.30", "2019.10.31", "2019.11.01", "2019.11.02",
"2019.11.03", "2019.11.04", "2019.11.05", "2019.11.06", "2019.11.07",
"2019.11.08", "2019.11.09", "2019.11.10", "2019.11.11", "2019.11.12",
"2019.11.13", "2019.11.14", "2019.11.15", "2019.11.16", "2019.11.17",
"2019.11.18", "2019.11.19", "2019.11.20", "2019.11.21", "2019.11.22",
"2019.11.23", "2019.11.24", "2019.11.25", "2019.11.26", "2019.11.27",
"2019.11.28", "2019.11.29", "2019.11.30", "2019.12.01", "2019.12.02",
"2019.12.03", "2019.12.04", "2019.12.05", "2019.12.06", "2019.12.07",
"2019.12.08", "2019.12.09", "2019.12.10", "2019.12.11", "2019.12.12",
"2019.12.13", "2019.12.14", "2019.12.15", "2019.12.16", "2019.12.17",
"2019.12.18", "2019.12.19", "2019.12.20", "2019.12.21", "2019.12.22",
"2019.12.23", "2019.12.24", "2019.12.25", "2019.12.26", "2019.12.27",
"2019.12.28", "2019.12.29", "2019.12.30", "2019.12.31", "2020.01.01",
"2020.01.02", "2020.01.03", "2020.01.04", "2020.01.05", "2020.01.06",
"2020.01.07", "2020.01.08", "2020.01.09", "2020.01.10", "2020.01.11",
"2020.01.12", "2020.01.13", "2020.01.14", "2020.01.15", "2020.01.16",
"2020.01.17", "2020.01.18", "2020.01.19", "2020.01.20", "2020.01.21",
"2020.01.22", "2020.01.23", "2020.01.24", "2020.01.25", "2020.01.26",
"2020.01.27", "2020.01.28", "2020.01.29", "2020.01.30", "2020.01.31",
"2020.02.01", "2020.02.02", "2020.02.03", "2020.02.04", "2020.02.05",
"2020.02.06", "2020.02.07", "2020.02.08", "2020.02.09", "2020.02.10",
"2020.02.11", "2020.02.12", "2020.02.13", "2020.02.14", "2020.02.15",
"2020.02.16", "2020.02.17", "2020.02.18", "2020.02.19", "2020.02.20",
"2020.02.21", "2020.02.22", "2020.02.23", "2020.02.24", "2020.02.25",
"2020.02.26", "2020.02.27", "2020.02.28", "2020.02.29", "2020.03.01",
"2020.03.02", "2020.03.03", "2020.03.04", "2020.03.05", "2020.03.06",
"2020.03.07", "2020.03.08", "2020.03.09", "2020.03.10", "2020.03.11",
"2020.03.12", "2020.03.13", "2020.03.14", "2020.03.15", "2020.03.16",
"2020.03.17", "2020.03.18", "2020.03.19", "2020.03.20", "2020.03.21",
"2020.03.22", "2020.03.23", "2020.03.24", "2020.03.25", "2020.03.26",
"2020.03.27", "2020.03.28", "2020.03.29", "2020.03.30", "2020.03.31"
), price_view = c(35.79, 180.16, 437.57, 10.3, 74.26, 79.8, 89.84,
121.24, 461.95, 142.06, 241.71, 52, 43.24, 41.16, 167.05, 764.06,
91.64, 189.82, 38.59, 152.64, 86.23, 321.33, 411.83, 256.88,
352.39, 76.32, 360.11, 123.53, 43.41, 149.38, 14.16, 489.07,
1661.74, 1253.07, 25.71, 154.42, 990.89, 1645.93, 144.12, 84.43,
240.25, 148.18, 41.13, 262.56, 168.78, 860.85, 239.31, 372.98,
165.64, 134.32, 20.7, 43.73, 765.76, 51.48, 599.49, 893.79, 155.29,
334.37, 46.82, 1814.72, 196.27, 1302.48, 40.16, 1161.68, 381.48,
184.48, 48.91, 221.11, 434.73, 149.27, 77.22, 882.49, 106.05,
669.23, 282.86, 179.67, 12.97, 460.24, 38.59, 278.26, 243.76,
1904.79, 84.93, 32.18, 25.71, 496.54, 29.6, 1466.83, 164.33,
234.76, 19.95, 308.37, 1130.02, 7.47, 79.8, 65.9, 746.45, 1347.78,
1270.82, 69.42, 231.41, 195.6, 715.33, 208.47, 720.46, 414.68,
24.45, 217.82, 434.45, 483.92, 1500.42, 318.15, 339.29, 267.45,
133.85, 9.03, 11.81, 280.57, 916.74, 58.51, 339.78, 33.98, 263.58,
19.31, 239.88, 489.07, 84.92, 344.9, 95.24, 99.1, 142.58, 480.58,
104.74, 14.83, 252, 1039.41, 28.3, 328.97, 341.55, 278.26, 43.73,
91.35, 102.32, 131.25, 155.15, 77.74, 14.67, 132.63, 1185.36,
1145.975, 1106.59, 849.42, 117.63, 171.32, 167.31, 252.23, 248.14,
111.15, 257.15, 27.62, 169.86, 101.89, 282.89, 298.57, 86.49,
196.32, 1415.45, 898.35, 334.6, 17.99, 13.62, 566.27, 60.41,
36.34, 62.04, 308.81, 32.95, 127.44, 836.57, 221.34, 360.34,
159.31, 20.57), view = c(1206151, 1152770, 1087372, 1344804,
1270060, 1262993, 1159265, 1323522, 1301376, 1240347, 1445162,
1432321, 1583572, 1376274, 1462409, 1443323, 1337174, 1413405,
1382403, 1443838, 1342668, 1353053, 1318395, 1252747, 1369922,
1288939, 1330209, 1220710, 1187883, 1169955, 1207854, 1402754,
1513400, 1524803, 1743304, 1670637, 1644359, 1748812, 1789808,
1783142, 1845552, 1907417, 1892753, 1920411, 2864410, 5691766,
5986292, 5759703, 1905351, 1627672, 1598554, 1573101, 1471242,
1474138, 1500022, 1496128, 1557252, 1547199, 1560191, 1727852,
1644405, 1706901, 1629904, 1547658, 1468085, 1540157, 1652208,
1725106, 1724452, 1627222, 1651328, 1605421, 1650612, 1634861,
1760750, 2167056, 2875847, 2780816, 2665285, 2528244, 2387520,
2340327, 2471739, 2372930, 2326654, 2322753, 2240514, 2058141,
2089081, 2474226, 2294820, 1603749, 1427733, 1700904, 1765457,
1754424, 1738774, 1696188, 1701769, 1585870, 1556542, 1557542,
1618230, 1645866, 1627433, 1612956, 1555416, 1773179, 1826768,
2021676, 2104199, 1801073, 1733142, 1593991, 1645225, 1557626,
1637470, 1721003, 1545472, 1594688, 1565742, 1651606, 1999670,
2217825, 1985751, 1680034, 1608904, 1620473, 1628906, 1726835,
1589058, 1714745, 1751044, 1896265, 2429526, 2268487, 1935249,
1916034, 2239698, 1916650, 1981570, 1948648, 1987134, 1749514,
1822349, 1830307, 1748590, 1734610, 1798308, 1399256, 1000204,
1257475, 1770064, 2416707, 2477258, 2487470, 2457500, 2210539,
2377633, 2026050, 2301337, 2218894, 2012789, 1700619, 1481115,
1562027, 1560348, 1338829, 1244973, 1142989, 1260747, 1316975,
1387394, 1319559, 1440470, 1451015, 1439649, 1390411, 1336076,
1369834, 1255626, 1244163, 1283731), price_cart = c(29.51, 1415.48,
99.86, 358.57, 617.51, 1052.79, 1747.79, 190.56, 128.28, 252.38,
250.91, 720.48, 33.42, 643, 191.77, 460.11, 408.5, 789.9, 577.94,
49.36, 380.7, 19.56, 994.86, 756.71, 223.66, 437.33, 1684.28,
366.16, 968.34, 1683.07, 550.77, 503.09, 29.09, 179.67, 210.62,
22.66, 131.66, 68.96, 360.06, 494.22, 1023.62, 1569.92, 28.29,
694.97, 127.05, 37.85, 282.89, 178.9, 913.28, 1022.42, 424.7,
573.7, 1029.34, 30.12, 20.82, 17.99, 107.53, 41.19, 85.82, 1002.55,
140.98, 167.03, 231.67, 25.71, 205.64, 30.81, 51.22, 65.9, 7.08,
308.63, 227.79, 16.22, 7.89, 62.52, 48.88, 586.63, 602.07, 1312.26,
128.32, 179.9, 849.42, 100.9, 1284.2, 12.84, 128.42, 59.18, 176.99,
38.02, 48.88, 694.54, 262.3, 1402.84, 1453.18, 3.84, 453.01,
76.93, 7.04, 865.93, 865.4, 40.75, 1423.07, 1534.66, 679.27,
11.25, 102.63, 436.3, 853.93, 694.97, 850.47, 477.49, 1234.97,
10.27, 23.94, 643.23, 89.84, 290.34, 320.99, 6.44, 140.28, 188.89,
56.88, 1326.31, 194.34, 140.28, 771.96, 140.03, 20.21, 1464.39,
59.18, 57.92, 1156.81, 50.43, 300.12, 38.1, 832.71, 57.91, 174.5,
100.36, 248.14, 109.34, 100.7, 242.7, 266.67, 592.01, 242.18,
22.66, 566.04, 38.61, 812.06, 490.33, 168.6, 172.03, 49.91, 16.73,
108.04, 347.47, 97.79, 111.15, 514.79, 126.1, 178.87, 870.03,
529.31, 43.5, 2110.48, 771.94, 15.32, 105.25, 7.14, 312.67, 61.75,
165.51, 48.37, 643.49, 303.48, 35.78, 154.42, 209.71, 76.69,
25.46, 1415.45, 123.53, 602.31), cart = c(16658, 17268, 19323,
43826, 35493, 32145, 18052, 18442, 18432, 18997, 21450, 20691,
24833, 44821, 49513, 45272, 40368, 40127, 39455, 40533, 36675,
36945, 36407, 35721, 36800, 34776, 34256, 17838, 17455, 16996,
16798, 18911, 19350, 20211, 21960, 19231, 19670, 19446, 77319,
70093, 71585, 75135, 69669, 71613, 170183, 481862, 405584, 426261,
83117, 72450, 72311, 75530, 70171, 64801, 68099, 71405, 71622,
71324, 71504, 92345, 81760, 84473, 80869, 70192, 66718, 71048,
83618, 84231, 80773, 80675, 81420, 78947, 80162, 82360, 86689,
109721, 183764, 155406, 146906, 137487, 127900, 124577, 127381,
126700, 124797, 127554, 123966, 120940, 127769, 148663, 148608,
119062, 57614, 71342, 95608, 80629, 78782, 79099, 77396, 74671,
72772, 74827, 72221, 73406, 72999, 71182, 70235, 79414, 104791,
103481, 102597, 94354, 90666, 83642, 83223, 73075, 73582, 73849,
70067, 71600, 72179, 130757, 208231, 169156, 137970, 116560,
104701, 102836, 101145, 101605, 90864, 92635, 95114, 100283,
158447, 131720, 118661, 126405, 132399, 98277, 96270, 95284,
96886, 89046, 91384, 89585, 83771, 83241, 84151, 62362.5, 40574,
48944, 81869, 146953, 135144, 132819, 134255, 131648, 141696,
122204, 122752, 120927, 112159, 102239, 95998, 97600, 99032,
79662, 76622, 69585, 73822, 74488, 75621, 69098, 73761, 76429,
75664, 77671, 77090, 77835, 68888, 69091, 73986), price_purchase = c(130.76,
419.6, 251.74, 252.88, 64.02, 272.59, 172.72, 88.81, 28.73, 1003.86,
346.47, 130.48, 29.86, 280.11, 358.57, 385.83, 287.61, 22.95,
58.08, 854.08, 28.28, 62.91, 994.86, 51.22, 9.01, 77.21, 244.15,
366.16, 366.8, 213.25, 35.52, 566.3, 35.78, 1106.82, 64.35, 722.18,
131.66, 166.1, 823.9, 138.23, 334.6, 328.19, 243.51, 488.8, 159.57,
106.8, 54.03, 27, 308.63, 1022.42, 463.31, 144.66, 44.53, 25.48,
126.18, 365.52, 133.92, 97.27, 12.84, 1002.55, 107.41, 132.31,
131.2, 789.57, 230.2, 12.36, 229.86, 1386.91, 154.19, 18.19,
76.96, 882.49, 191.55, 46.08, 24.17, 102.65, 326.62, 924.06,
923.73, 88.29, 41.16, 128.42, 326.88, 137.96, 30.68, 108.88,
181.19, 241.34, 128.32, 137.46, 1279.81, 643.23, 1275.16, 717.245,
159.33, 745.37, 288.27, 177.26, 168.58, 66.85, 331.51, 437.31,
643.23, 9.3, 0.85, 436.3, 105.51, 7.7, 79.44, 1321.37, 160.89,
107.21, 172.25, 514.79, 141.06, 900.64, 153.22, 924.4, 176.34,
94.98, 162.6, 1326.25, 39.9, 38.15, 2162.22, 180.95, 153.41,
720.48, 720.48, 15.42, 140.28, 514.02, 720.47, 174.7, 197.69,
411.08, 741.07, 230.12, 501.89, 109.34, 643.26, 23.17, 242.48,
1317.36, 69.76, 178.11, 153.55, 32.18, 812.06, 482.7, 153.34,
172.03, 128.68, 939.54, 108.04, 165.89, 56.63, 43.76, 171.17,
98.59, 21.95, 280.28, 181.47, 730.01, 159.31, 60.75, 31.15, 1412.39,
7.14, 942.84, 321.06, 165.51, 284.95, 169.42, 303.48, 224.3,
416.43, 385.85, 492.08, 334.6, 1415.45, 123.53, 308.55), purchase = c(19307,
19469, 19255, 27041, 23494, 22171, 21378, 23072, 22748, 21993,
26224, 25373, 29561, 28405, 26372, 31394, 28318, 25850, 24657,
25098, 25167, 25385, 24731, 23999, 23929, 22653, 23403, 21112,
20374, 20817, 20099, 22458, 21864, 22145, 26889, 24875, 25319,
24863, 25714, 22768, 22878, 24931, 22725, 22548, 22124, 45185.5,
68247, 185195, 28537, 24967, 24947, 25266, 24187, 22243, 23163,
24827, 24226, 24443, 24305, 32107, 28178, 28345, 28548, 24358,
24473, 25469, 27505, 27012, 25766, 26802, 27059, 25906, 26044,
26712, 26559, 35077, 63796, 51899, 49578, 48212, 46405, 44255,
44719, 46602, 44917, 44949, 44154, 43081, 45287, 49597, 50729,
38233, 3574, 13975.5, 24377, 28938, 28427, 28875, 27722, 27510,
26492, 27481, 26059, 25869, 27525, 26322, 27121, 29614, 35086,
32884, 32548, 32619, 31698, 30089, 30398, 27579, 26662, 26880,
27052, 26841, 27403, 27612, 33750, 32536, 32308, 28645, 27652,
28276, 28533, 28426, 25379, 26027, 46480, 60013, 102117, 83216,
76048, 72365, 87586, 63260, 36377, 31438, 31258, 29324, 28946,
29017, 27884, 28063, 27809, 27649.5, 27490, 26316, 31358, 55087,
46356, 45228, 44406, 43521, 45501, 40281, 41091, 41681, 39266,
36268, 34754, 35341, 35943, 28852, 27810, 25186, 25501, 26232,
25775, 23698, 25314, 25960, 26259, 27487, 26966, 25817, 21294,
22704, 23997), ctr = c(0.0157890561813006, 0.0166396305077271,
0.0173986509381537, 0.0194731497951218, 0.0179954394804347, 0.01711863909483,
0.0181582360570687, 0.0171927115779559, 0.0172358403646591, 0.0174638541971058,
0.0178806664612045, 0.017462347179514, 0.0183790774089859, 0.0199881077619723,
0.0174426987635606, 0.021089685240109, 0.0205569049800296, 0.0177842661874661,
0.0173413941476575, 0.0169081718788632, 0.0182456430344012, 0.0182626162052032,
0.0182543279386951, 0.0186259961442581, 0.0170104683085926, 0.0171132003490177,
0.0171517774365777, 0.0170457664943143, 0.016903142521019, 0.0175382134561578,
0.0164120092891695, 0.0157969704536582, 0.014264557168488, 0.0143332034531726,
0.0152322825367764, 0.0147200846456646, 0.0152154800186776, 0.0140607309566817,
0.0137719608789332, 0.0122855439272407, 0.0119334194687182, 0.0125752060979989,
0.01158007808718, 0.0113191407332442, 0.00729059877222415, 0.00731911608538772,
0.0106771470535411, 0.029937936916542, 0.0143512493034839, 0.0146854166936255,
0.0149305898441825, 0.015325442746133, 0.015691446743994, 0.0144534643673336,
0.0147711815606066, 0.0158382630541111, 0.0148728508159624, 0.015102040564144,
0.0148955533969277, 0.0176392994824187, 0.0163240478169816, 0.0158230497930639,
0.0166871934499785, 0.0150557839107457, 0.0159453688844757, 0.0158074236363467,
0.0158454822084702, 0.0149292254566175, 0.0142730130593139, 0.0156929838274791,
0.0156162350209032, 0.0153802494466767, 0.0150476029799385, 0.015555365325721,
0.0143761174252573, 0.0154064275947974, 0.0208510166815324, 0.0176754346231314,
0.0176296702464377, 0.01808584587117, 0.0184482114318881, 0.0179540460804964,
0.0172054387638893, 0.0186435592467685, 0.0183226179107802, 0.0183442319676677,
0.0186738733252132, 0.0197702609494553, 0.0204285359857455, 0.0189093019186096,
0.0207614056972417, 0.0221922195760301, 0.00240617175649865,
0.00788575626634226, 0.01309841408011, 0.0157695717780358, 0.0156402333683254,
0.0162649757475833, 0.0155814665868539, 0.0165668899473124, 0.0162596037350689,
0.0168350415867981, 0.0154154128099543, 0.0150464847912372, 0.0161870630522126,
0.0156293605393382, 0.0166831626222356, 0.0159851624182969, 0.0181646017543342,
0.0154736802975027, 0.0147489845006063, 0.0172093148404027, 0.0173801189598905,
0.0179353887292393, 0.017586875624838, 0.0169123585500959, 0.0155822266067893,
0.0149761651657073, 0.0167448758587691, 0.0161082597966258, 0.0167303551270177,
0.0154917937591837, 0.015286011465188, 0.0136306070303869, 0.0152129210946259,
0.0159440585908669, 0.0161367409642245, 0.0164079686231546, 0.016492577386447,
0.0155465861608803, 0.0151072490270382, 0.0144004027929932, 0.0251766100192941,
0.0300583807652007, 0.0394582941939502, 0.0346703430162482, 0.0370259651104479,
0.0354306787130485, 0.0369234479028471, 0.0313956783546004, 0.0175071227813499,
0.0153811379243536, 0.0149988963637585, 0.0159494386911496, 0.0151254119566314,
0.0151138709885764, 0.0152175253675449, 0.015437458845637, 0.0147726989007463,
0.02059282, 0.0264129334017437, 0.0201436139554002, 0.0169325780144314,
0.0214876387664511, 0.0177445890793224, 0.0172606914733451, 0.017133563936406,
0.0185813515317095, 0.0180607614170281, 0.0187505760492009, 0.0169511102933927,
0.0178137558385877, 0.0184785698285323, 0.0201169476464591, 0.0220364679005246,
0.0212945438945016, 0.021660499704709, 0.0203399246100257, 0.021042755155702,
0.0207706911083365, 0.0191080416224264, 0.0188521002714409, 0.0176177277744931,
0.0170654092407268, 0.0167173964870618, 0.0169957130997929, 0.0173290930652611,
0.018723068602435, 0.0190819762151085, 0.0178334964691514, 0.0160768402598991,
0.0172883539665594, 0.0176745227466401)), row.names = c(NA, -183L
), class = "data.frame")

Error no-more-error-handlers-available-recursive-errors-invoking-abort-restart when calculating similarity by row of a 32000 row data set

I am trying to calculate similarity between rows on data set that has 11 variables in columns (all numeric) and has 32000 rows. I find that the code below runs fine when I give it a 100 row or so subset of the data but when I give it the whole set, it seems to run fine for a while (although it uses a lot of memory) but then a few hours in it gives me the " no-more-error-handlers-available-recursive-errors-invoking-abort-restart" error. How can I avoid this? I have searched for similar situations but cannot seem to find a fix.
Here's the output from dput (of the first 200 rows):
structure(list(Corrected.Diameter.Pixels = c(12.19019, 68.27398,
47.76143, 73.22346, 12.19019, 68.27398, 47.76143, 73.22346, 22.75866,
29.18328, 8.36828, 24.04665, 46.39632, 17.54956, 8.48163, 34.8317,
63.37687, 21.19493, 30.39247, 50.77077, 11.97492, 12.06298, 12.25475,
47.38221, 32.43994, 28.94985, 24.2578, 6.54314, 8.15978, 5.86137,
10.79281, 45.88894, 45.61855, 62.30688, 26.97145, 22.74422, 14.71437,
10.85698, 57.38691, 49.8456, 10.16822, 6.44511, 17.13741, 82.2915,
30.46339, 26.88251, 13.60706, 26.89802, 9.94159, 14.4176, 69.87079,
20.82549, 12.82834, 56.12008, 42.99599, 21.41007, 28.61327, 31.16904,
45.71646, 5.99735, 8.20189, 8.59096, 33.17984, 39.97919, 16.47927,
62.84838, 46.17857, 8.34924, 21.1896, 18.83077, 26.87241, 17.48091,
29.38473, 24.51047, 10.99448, 45.74561, 18.83606, 48.27098, 34.10088,
27.26335, 47.261, 19.94131, 11.83929, 45.76572, 31.26533, 37.23263,
66.99194, 37.03562, 37.23263, 66.99194, 37.03562, 48.47576, 26.91966,
9.49569, 3.85533, 17.35284, 20.63553, 35.38634, 30.92475, 39.1207,
40.94417, 7.05849, 9.33047, 48.40907, 26.53372, 23.47957, 4.95074,
26.20909, 43.91702, 44.50182, 12.40077, 27.13945, 54.92627, 69.57408,
22.55181, 19.8885, 36.79568, 14.14961, 21.97367, 13.65241, 32.21456,
26.86064, 79.45784, 32.50686, 17.62748, 33.22018, 18.34666, 40.1397,
42.19999, 17.53833, 24.99026, 21.5522, 26.52919, 20.83556, 10.15603,
32.3793, 29.88744, 9.41774, 18.42085, 54.77612, 20.76089, 5.18625,
26.73453, 7.16143, 67.42748, 19.83195, 29.55424, 25.57784, 34.89938,
47.09778, 50.03208, 52.917, 34.84761, 11.71751, 43.0097, 10.7626,
19.80249, 5.27751, 29.94862, 6.53097, 35.8462, 44.63104, 16.06905,
15.96641, 49.53817, 22.80723, 26.74212, 22.07261, 6.76985, 28.21919,
19.92225, 31.41192, 38.10348, 66.85515, 23.34814, 31.64893, 9.29965,
9.29965, 28.3982, 10.8524, 42.95194, 35.25589, 32.39711, 8.73128,
6.23991, 40.09681, 24.12972, 35.72366, 13.16424, 10.16089, 14.49837,
8.83096, 28.32626, 25.79169, 40.59262, 5.29257, 66.95081, 23.22116,
36.50169, 12.97023), Contour.Slopes.Focus = c(4.3136, 25.36804,
10.92002, 2.12329, 4.3136, 25.36804, 10.92002, 2.12329, 4.30158,
6.35542, 2.11506, 3.71257, 2.89324, 4.64909, 2.70284, 2.12156,
4.55881, 9.37401, 14.45324, 33.61269, 8.59098, 4.57816, 3.48318,
3.75199, 11.25647, 16.81135, 10.61942, 2.23302, 2.87025, 2.9964,
4.05464, 2.76692, 10.31498, 7.45807, 7.63816, 10.68314, 3.13737,
3.08689, 18.50534, 15.5981, 3.95702, 2.37803, 5.98943, 23.67886,
7.09568, 22.48242, 3.29837, 2.68711, 2.16861, 6.44475, 7.15496,
2.34112, 2.06893, 3.84312, 2.08664, 4.02224, 3.72601, 4.11803,
26.3045, 2.87624, 3.98579, 3.04367, 3.39529, 5.05169, 3.61365,
19.98456, 14.06127, 2.22868, 4.26763, 10.38651, 19.54448, 3.43225,
2.41181, 3.16934, 3.82808, 23.9729, 7.45576, 2.07306, 21.02317,
5.61264, 2.05496, 2.5897, 7.24035, 2.0526, 2.10069, 2.79483,
2.55247, 2.3568, 2.79483, 2.55247, 2.3568, 15.50758, 17.59354,
4.46851, 2.5979, 2.13469, 8.90064, 11.08931, 6.44809, 4.2927,
3.47038, 5.40188, 2.67097, 3.16027, 2.3512, 19.05212, 2.0965,
15.44096, 3.41642, 3.37477, 2.9116, 4.33822, 4.91543, 5.14467,
4.45434, 9.14479, 15.53937, 4.55359, 3.43464, 4.41869, 4.44294,
6.91779, 17.98987, 3.99183, 4.33946, 8.10813, 6.29913, 15.06431,
11.24421, 2.96062, 7.0508, 2.05813, 5.67925, 5.20416, 3.78266,
3.33255, 3.41214, 4.15454, 4.92729, 2.06845, 3.48458, 2.37768,
12.21983, 3.67568, 2.92242, 4.18589, 10.19353, 5.37037, 3.74818,
2.99934, 23.26076, 4.12993, 2.06789, 2.88138, 2.62313, 5.04652,
6.90301, 2.13891, 10.06989, 2.60516, 11.75681, 4.68333, 2.66465,
3.42183, 20.50746, 10.14104, 16.13318, 11.83242, 2.9538, 6.09976,
2.1777, 10.97297, 3.66962, 2.85015, 7.96284, 6.78556, 3.17541,
3.17541, 3.39588, 2.18294, 2.48335, 2.29208, 3.46203, 2.05496,
4.23799, 18.35541, 3.36715, 2.48819, 5.91993, 2.83554, 3.1364,
2.14744, 7.4286, 8.63987, 2.72886, 2.09831, 3.33151, 2.33972,
2.36506, 2.34587), Center.Slopes.Focus = c(3.93569, 17.48096,
5.24481, 2.04047, 3.93569, 17.48096, 5.24481, 2.04047, 5.47357,
6.4319, 1.79427, 7.45559, 2.5578, 5.22557, 3.51968, 1.93345,
4.34895, 8.61821, 16.66679, 27.49446, 4.6633, 3.97783, 3.08418,
3.92054, 7.95604, 11.23728, 10.3449, 2.66223, 1.91881, 2.45007,
4.57762, 11.9696, 11.12726, 16.20871, 6.46894, 9.12789, 2.72591,
2.04958, 8.06506, 16.67047, 2.54557, 2.77529, 8.36701, 16.81984,
9.87396, 14.59361, 2.62569, 2.09149, 2.31127, 6.00849, 4.72961,
2.20902, 1.91998, 4.06132, 4.57347, 2.41457, 8.59905, 7.57387,
20.21926, 2.76708, 5.78741, 2.62601, 2.14974, 5.08722, 4.79306,
19.08451, 12.99397, 1.56353, 2.62428, 8.48093, 12.61335, 2.1338,
2.06289, 2.62905, 2.74988, 18.2123, 6.72277, 8.16906, 15.65421,
8.433, 1.79583, 2.34758, 6.86255, 2.15922, 2.03373, 6.4009, 2.4897,
1.83251, 6.4009, 2.4897, 1.83251, 14.08499, 12.91235, 4.07487,
2.21547, 2.07308, 8.29071, 12.91634, 3.82692, 8.43121, 2.97828,
2.06107, 2.32977, 9.12194, 3.18728, 9.84288, 1.65122, 10.59612,
2.73903, 2.4703, 3.2595, 7.86804, 4.82543, 13.92432, 2.90592,
10.49815, 16.18525, 4.74386, 2.05197, 4.74073, 8.98564, 7.67054,
18.01745, 9.98196, 4.22172, 5.13628, 6.88238, 19.92256, 7.89053,
2.61123, 7.40615, 2.05687, 3.51666, 2.89755, 4.73519, 2.38595,
2.68162, 2.87286, 6.4738, 1.96502, 1.97548, 3.03498, 9.24552,
5.75448, 3.67827, 2.51072, 6.77992, 3.50957, 2.89675, 2.46563,
9.0731, 15.51868, 2.08016, 2.3717, 2.50213, 6.43711, 8.18983,
2.0291, 10.35156, 2.10799, 15.97664, 12.49868, 2.313, 2.79687,
16.33956, 8.74962, 10.94272, 11.17668, 2.41257, 9.07319, 2.03425,
11.82396, 6.73517, 3.15668, 6.56735, 5.03541, 4.49669, 4.49669,
2.72608, 1.69062, 2.10132, 2.19671, 7.70856, 2.2093, 2.21091,
9.58419, 2.56105, 2.24081, 8.01145, 1.86848, 5.16671, 1.84117,
10.75741, 6.8423, 8.78951, 1.41239, 3.76303, 2.01126, 6.49525,
2.7017), Hollowness = c(0.52616, 0.37595, 0.68236, 1.05521, 0.52616,
0.37595, 0.68236, 1.05521, 0.59558, 0.4549, 1.02565, 0.3604,
0.99252, 0.32438, 0.35027, 1.13396, 0.83684, 0.50703, 0.47906,
0.45009, 1.64756, 0.4937, 0.62383, 0.99405, 0.90267, 0.33659,
0.71159, 1.07434, 1.12326, 1.22678, 0.5452, 0.49734, 0.38534,
0.43372, 0.94245, 0.59777, 1.01532, 1.10199, 0.3537, 0.45786,
1.05529, 1.12316, 0.89381, 0.4182, 0.428, 0.4253, 1.16391, 1.09938,
1.06376, 0.72487, 0.72082, 1.13886, 1.0306, 0.95027, 0.61007,
1.04794, 0.53296, 0.7093, 0.38053, 1.12633, 1.176, 1.18966, 0.9997,
0.99609, 0.419, 0.3866, 0.31941, 1.20569, 1.0829, 0.38096, 0.37841,
1.04863, 1.10137, 1.09964, 1.10824, 0.36615, 0.54242, 0.49812,
0.44068, 0.39192, 1.13573, 1.01345, 0.7259, 1.13595, 1.0808,
0.52761, 1.01203, 1.14371, 0.52761, 1.01203, 1.14371, 0.49288,
0.3546, 0.67057, 1.18182, 1.06765, 0.4982, 0.39265, 1.02071,
0.335, 1.00649, 1.32267, 0.78909, 0.41254, 0.65074, 1.29995,
1.02355, 0.53661, 1.07034, 1.03299, 0.53751, 0.32311, 0.88956,
0.50373, 1.00173, 0.38705, 0.39043, 0.40523, 1.06139, 1.19208,
0.42918, 0.95767, 0.39285, 0.4552, 1.09705, 0.94378, 1.01756,
0.45299, 0.5367, 0.68791, 0.35151, 1.02035, 1.02949, 1.04821,
0.99493, 1.14203, 1.05309, 0.67721, 0.26618, 1.17289, 1.0328,
1.1094, 0.3134, 0.88318, 0.9364, 1.0529, 0.95072, 1.02907, 0.99449,
1.00704, 0.46449, 0.46578, 1.13423, 1.05147, 1.0165, 1.12441,
0.74086, 0.83732, 0.40251, 1.18107, 0.48469, 0.51293, 1.01394,
1.05956, 0.34575, 0.63879, 0.36294, 0.37995, 1.15976, 0.4365,
1.09591, 0.35233, 0.53878, 0.92687, 0.22597, 1.03128, 0.43234,
0.43234, 1.0036, 1.1369, 1.15127, 1.16154, 0.51647, 1.15784,
1.22872, 0.55414, 1.03428, 1.10664, 0.72898, 1.09186, 0.31093,
1.08589, 0.35295, 0.98539, 0.42157, 0.90694, 0.8678, 1.04131,
0.44712, 0.92105), Ellipse.Best.Fit = c(0.12686, 0.06242, 0.0399,
0.08292, 0.12686, 0.06242, 0.0399, 0.08292, 0.0869, 0.10098,
0.22388, 0.09176, 0.06762, 0.10612, 0.13379, 0.09515, 0.0345,
0.09968, 0.1, 0.06043, 0.21739, 0.11979, 0.13131, 0.04318, 0.05479,
0.09419, 0.0825, 0.16048, 0.11341, 0.15954, 0.11861, 0.10554,
0.06632, 0.04445, 0.0692, 0.10756, 0.09534, 0.09852, 0.04601,
0.10938, 0.11533, 0.16893, 0.09193, 0.05332, 0.09533, 0.12059,
0.08821, 0.08091, 0.12238, 0.1066, 0.03199, 0.12503, 0.12608,
0.04762, 0.07634, 0.07655, 0.1012, 0.13079, 0.07817, 0.19241,
0.14994, 0.09514, 0.0654, 0.05102, 0.0964, 0.04918, 0.07226,
0.23066, 0.08644, 0.09246, 0.09367, 0.08282, 0.10171, 0.10327,
0.15858, 0.08353, 0.1072, 0.14693, 0.09354, 0.09023, 0.08682,
0.13214, 0.12566, 0.08757, 0.11074, 0.07518, 0.06005, 0.08598,
0.07518, 0.06005, 0.08598, 0.09446, 0.10164, 0.11482, 0.32865,
0.16509, 0.13208, 0.10245, 0.06301, 0.09023, 0.0626, 0.10438,
0.12711, 0.05577, 0.08548, 0.167, 0.33919, 0.06765, 0.09811,
0.0835, 0.13114, 0.11114, 0.03856, 0.06691, 0.13623, 0.11268,
0.07032, 0.12544, 0.08775, 0.10234, 0.11976, 0.06556, 0.05994,
0.10356, 0.10274, 0.05077, 0.08209, 0.07633, 0.11856, 0.10702,
0.08867, 0.13358, 0.07553, 0.07519, 0.14972, 0.09807, 0.08352,
0.17224, 0.09787, 0.08938, 0.07829, 0.12535, 0.09875, 0.17592,
0.04693, 0.08057, 0.06502, 0.07306, 0.06113, 0.08202, 0.07735,
0.05906, 0.09861, 0.1093, 0.06698, 0.2418, 0.09116, 0.47288,
0.10737, 0.1312, 0.11815, 0.10209, 0.09471, 0.085, 0.06287, 0.10586,
0.08374, 0.10256, 0.17284, 0.10033, 0.13071, 0.13577, 0.07558,
0.04658, 0.1316, 0.06445, 0.11592, 0.11592, 0.06354, 0.14166,
0.07837, 0.09737, 0.10549, 0.15289, 0.1791, 0.09515, 0.07661,
0.0822, 0.06911, 0.09861, 0.08877, 0.11622, 0.10625, 0.08489,
0.09665, 0.47287, 0.03571, 0.10801, 0.09309, 0.12792), Ellipse.Minor.Major = c(0.97484,
0.87149, 0.97655, 0.94141, 0.97484, 0.87149, 0.97655, 0.94141,
0.93112, 0.92623, 0.68616, 0.94106, 0.96672, 0.9292, 0.98265,
0.9126, 0.94138, 0.89859, 0.86031, 0.90321, 0.41054, 0.74691,
0.79333, 0.91219, 0.92769, 0.9378, 0.80746, 0.6985, 0.87451,
0.65704, 0.88385, 0.78848, 0.90607, 0.95438, 0.96349, 0.79419,
0.95932, 0.975, 0.94095, 0.78623, 0.79446, 0.67024, 0.8857, 0.86376,
0.92037, 0.87893, 0.89415, 0.95029, 0.85487, 0.78298, 0.97361,
0.94482, 0.92723, 0.93701, 0.96975, 0.83343, 0.97602, 0.86225,
0.89309, 0.72466, 0.88954, 0.92641, 0.9625, 0.93398, 0.90222,
0.93317, 0.91668, 0.70301, 0.89221, 0.97242, 0.86125, 0.88034,
0.97066, 0.98221, 0.64364, 0.88755, 0.94707, 0.75962, 0.86182,
0.94778, 0.99107, 0.9868, 0.90752, 0.95454, 0.94929, 0.9311,
0.93094, 0.98346, 0.9311, 0.93094, 0.98346, 0.81644, 0.91833,
0.85131, 0.5621, 0.91423, 0.97931, 0.86834, 0.95444, 0.87997,
0.94614, 0.78038, 0.87974, 0.98127, 0.9534, 0.58513, 0.69292,
0.88587, 0.8617, 0.94961, 0.82541, 0.96436, 0.94692, 0.8396,
0.82141, 0.93629, 0.93202, 0.952, 0.9566, 0.93307, 0.87949, 0.93758,
0.87382, 0.84368, 0.95025, 0.9825, 0.95884, 0.91336, 0.87575,
0.913, 0.95621, 0.94325, 0.95315, 0.92453, 0.81239, 0.97447,
0.93389, 0.67998, 0.93045, 0.93555, 0.87384, 0.56281, 0.97646,
0.94133, 0.98437, 0.93116, 0.96405, 0.92715, 0.93464, 0.96043,
0.9413, 0.93246, 0.952, 0.96144, 0.97202, 0.76449, 0.84536, 0.44224,
0.95637, 0.88116, 0.78823, 0.79391, 0.9312, 0.92753, 0.95135,
0.7575, 0.88473, 0.981, 0.6237, 0.96012, 0.89053, 0.88827, 0.93739,
0.93825, 0.92609, 0.94267, 0.90009, 0.90009, 0.9272, 0.92499,
0.98394, 0.9474, 0.91858, 0.9143, 0.88942, 0.89033, 0.95715,
0.94818, 0.91697, 0.93259, 0.95047, 0.9039, 0.88334, 0.92442,
0.80908, 0.57049, 0.9211, 0.95429, 0.9716, 0.84649), Ellipse.Angle = c(-0.26549,
47.87729, 32.81444, 0.41248, -0.26549, 47.87729, 32.81444, 0.41248,
-84.62616, 33.2692, 30.52107, 59.02478, 10.3997, 15.29359, 79.84372,
17.00218, 1.69621, 11.81746, -79.6879, 87.38062, 5.98631, 6.19804,
61.87537, 35.6207, 73.81332, 79.533, -3.37468, -3.46536, 4.92232,
4.54409, -88.30457, -81.54878, 37.10699, 77.15878, 9.88208, 9.27422,
28.16016, 2.34975, 16.60769, 57.14313, 3.7687, 0.27241, 0.7656,
-73.19455, 68.05791, -86.29077, 6.0115, 41.2951, 7.73961, 3.2164,
25.34626, 2.0231, 70.4911, 26.23402, 62.33054, 6.76939, 25.93145,
56.36418, -87.88627, -21.23725, -85.37364, 32.00761, 35.25288,
-79.7581, -24.24713, 71.69191, 36.5758, -26.63295, 8.81189, -5.42305,
65.88388, 4.44144, -84.979, -65.68634, -1.76115, -62.38568, -82.90343,
-82.59503, 68.85648, 82.84439, 50.71829, -32.7039, 27.42184,
36.22755, 38.5052, 54.30583, 11.04899, -31.53599, 54.30583, 11.04899,
-31.53599, 79.05298, -88.21964, -11.13059, 62.49229, 67.14563,
13.70192, -89.29182, 20.07127, -88.92424, 15.24553, 16.53206,
-25.23101, -69.6471, 32.34082, 22.7326, -36.32436, 5.91715, 1.00293,
26.09496, -0.6578, 89.6088, 19.4799, 87.81131, -32.30591, 61.31126,
-70.51817, -3.67815, 41.6709, 83.77933, 63.97905, 84.87115, -65.22361,
79.98466, 51.07666, 55.46004, 32.32834, -81.63506, 78.16069,
-32.71989, -9.99143, 43.63046, 69.51038, 65.42319, -0.99499,
46.87006, 67.95813, -0.76465, 9.91245, 2.72037, 10.02576, -3.10905,
-60.15891, 68.70296, -11.16678, 2.68246, 15.47439, 11.88357,
-13.77675, 10.44487, -59.76076, 62.30257, 43.41193, 8.58439,
-31.92735, -19.00837, -7.67491, -77.03242, -63.67503, 5.00948,
-87.86459, 70.2644, 42.20956, -88.13396, 34.0519, -6.83882, 81.47803,
-24.68556, -8.03435, 25.76215, 71.77255, -75.49636, 51.86375,
-0.6648, -0.41131, -1.30077, -5.19302, -5.19302, 46.07491, 34.30194,
25.71502, 34.11366, 38.96255, 58.57315, -18.01156, -52.6637,
-82.42259, 29.84653, -6.24498, 54.00777, 8.53305, 5.90916, -67.80801,
10.97036, 75.45062, -53.53974, 11.68803, -72.71574, 67.94856,
49.56824), Contour.Circularity = c(0.57984, 0.31259, 0.57614,
0.32992, 0.57984, 0.31259, 0.57614, 0.32992, 0.49579, 0.38203,
0.16996, 0.35673, 0.44124, 0.44364, 0.55642, 0.32538, 0.49707,
0.50238, 0.35861, 0.36499, 0.39239, 0.69829, 0.4429, 0.47363,
0.58054, 0.51238, 0.59219, 0.54507, 0.68784, 0.60861, 0.57437,
0.17506, 0.38936, 0.3442, 0.60931, 0.54726, 0.58091, 0.56619,
0.47722, 0.18886, 0.63755, 0.54623, 0.65334, 0.27551, 0.33937,
0.39101, 0.54654, 0.34939, 0.38502, 0.62972, 0.55753, 0.35239,
0.36218, 0.52252, 0.23757, 0.58587, 0.2709, 0.21829, 0.43872,
0.47969, 0.59459, 0.6124, 0.51182, 0.54793, 0.41998, 0.35186,
0.38025, 0.27553, 0.48553, 0.56306, 0.51686, 0.54781, 0.27138,
0.49565, 0.46858, 0.36787, 0.51173, 0.12335, 0.3182, 0.30911,
0.27854, 0.37153, 0.65988, 0.28953, 0.31494, 0.27995, 0.39859,
0.3481, 0.27995, 0.39859, 0.3481, 0.33752, 0.47926, 0.65219,
0.28976, 0.25785, 0.39166, 0.3605, 0.52565, 0.23279, 0.46146,
0.7376, 0.39896, 0.31347, 0.29913, 0.36793, 0.11098, 0.72137,
0.38094, 0.52785, 0.36745, 0.33825, 0.535, 0.1863, 0.44796, 0.43577,
0.4647, 0.4649, 0.55783, 0.70578, 0.19916, 0.5446, 0.23488, 0.26414,
0.4931, 0.65159, 0.54989, 0.37499, 0.34683, 0.29308, 0.41818,
0.34788, 0.59432, 0.58566, 0.53021, 0.45434, 0.43537, 0.4838,
0.58022, 0.27608, 0.47766, 0.64015, 0.4575, 0.56754, 0.46998,
0.49236, 0.66591, 0.60207, 0.53154, 0.46698, 0.37326, 0.29032,
0.35785, 0.50671, 0.41213, 0.3326, 0.65913, 0.02252, 0.40109,
0.60521, 0.23903, 0.22271, 0.41207, 0.56428, 0.48571, 0.49939,
0.5455, 0.54608, 0.43553, 0.34283, 0.35736, 0.29468, 0.41175,
0.4598, 0.44601, 0.52998, 0.55968, 0.55968, 0.52693, 0.40363,
0.37611, 0.29309, 0.26134, 0.4002, 0.56722, 0.33748, 0.54575,
0.40915, 0.83766, 0.56029, 0.52272, 0.49637, 0.31738, 0.48753,
0.19278, 0.01605, 0.41144, 0.37996, 0.17427, 0.33571), Convex.Hull.Circularity = c(0.95452,
0.97756, 0.98551, 0.96918, 0.95452, 0.97756, 0.98551, 0.96918,
0.96737, 0.96509, 0.87561, 0.97622, 0.97008, 0.97073, 0.93563,
0.97727, 0.989, 0.97048, 0.96045, 0.97949, 0.69613, 0.9439, 0.94336,
0.98016, 0.98301, 0.96922, 0.95774, 0.89566, 0.95053, 0.86748,
0.95847, 0.93995, 0.97184, 0.98013, 0.97682, 0.95865, 0.962,
0.95634, 0.98045, 0.9326, 0.94343, 0.90115, 0.96056, 0.97901,
0.95421, 0.95998, 0.97379, 0.97555, 0.97097, 0.95375, 0.9898,
0.95915, 0.95802, 0.97736, 0.97341, 0.96096, 0.96343, 0.93928,
0.96931, 0.9087, 0.92696, 0.96462, 0.97702, 0.98306, 0.96978,
0.97862, 0.97239, 0.88828, 0.95851, 0.96804, 0.96829, 0.96696,
0.9547, 0.95874, 0.88022, 0.96627, 0.96874, 0.93356, 0.96086,
0.97163, 0.96986, 0.94628, 0.93651, 0.96472, 0.95908, 0.98232,
0.97587, 0.96754, 0.98232, 0.97587, 0.96754, 0.96678, 0.95683,
0.94982, 0.79142, 0.93517, 0.96691, 0.95162, 0.98091, 0.96642,
0.9783, 0.8499, 0.96012, 0.9823, 0.96049, 0.83793, 0.86966, 0.97624,
0.95089, 0.97351, 0.94081, 0.95098, 0.98555, 0.96934, 0.93905,
0.96482, 0.97905, 0.96239, 0.96955, 0.9676, 0.95003, 0.97403,
0.97745, 0.93772, 0.94393, 0.98481, 0.97512, 0.97424, 0.95336,
0.95927, 0.96911, 0.95691, 0.98043, 0.97289, 0.92612, 0.96436,
0.97502, 0.88734, 0.95745, 0.9639, 0.96252, 0.84067, 0.9671,
0.9475, 0.98454, 0.97523, 0.96989, 0.97203, 0.97307, 0.97211,
0.96897, 0.97704, 0.96131, 0.95667, 0.97914, 0.88039, 0.94506,
0.66942, 0.95603, 0.93732, 0.93096, 0.9365, 0.96493, 0.97557,
0.97841, 0.93981, 0.95348, 0.96814, 0.85398, 0.97675, 0.92406,
0.94602, 0.97492, 0.98237, 0.95324, 0.97392, 0.93816, 0.93816,
0.97622, 0.95486, 0.96851, 0.96179, 0.95823, 0.94437, 0.87086,
0.95986, 0.97093, 0.97256, 0.93827, 0.95562, 0.9785, 0.96941,
0.96207, 0.968, 0.95264, 0.82615, 0.98268, 0.95164, 0.96836,
0.94015), Box.H.W.Ratio = c(0.90476, 0.98701, 0.96552, 0.9322,
0.90476, 0.98701, 0.96552, 0.9322, 1.05714, 1, 1.04545, 1.025,
0.94737, 1, 1.05263, 0.95385, 0.93182, 0.96429, 1.14706, 1.07407,
0.43478, 0.8, 1.19048, 0.94444, 1.05263, 1, 0.8125, 0.66667,
0.84211, 0.71429, 1.11765, 1.23529, 0.94737, 1.06494, 0.97222,
0.93103, 0.9, 0.95455, 0.97015, 1.15789, 0.78947, 0.70588, 0.92,
1.13636, 1.075, 1.13793, 0.88889, 0.96, 0.875, 0.85714, 0.97727,
0.93333, 1.03448, 0.93976, 1.02667, 0.81579, 0.92, 1.08163, 1.16667,
0.8, 1.25, 1.05882, 0.96296, 1.05455, 0.93333, 1.07246, 1, 0.875,
0.91429, 1, 1.06897, 0.875, 1.03571, 1, 0.66667, 1.125, 1.08333,
1.27273, 1.13158, 1.07692, 1, 1.05, 1, 0.96341, 1, 1.04918, 0.90566,
0.9697, 1.04918, 0.90566, 0.9697, 1.14815, 1.10345, 0.8125, 1.33333,
1.05263, 1, 1.16667, 0.95349, 1.14035, 0.98438, 0.63636, 0.91304,
1.01351, 0.96154, 0.67647, 0.94118, 0.90323, 0.83784, 0.94286,
0.88889, 1.11905, 0.96053, 1.17442, 0.87179, 1.04, 1, 0.95652,
0.94737, 1.04762, 1.125, 1.02778, 1.07865, 1.27083, 0.93548,
1, 0.92593, 1.06667, 1.12, 1, 0.94444, 1, 1, 1.03333, 0.84211,
0.96296, 1.04167, 0.72222, 0.93103, 0.95745, 0.84211, 0.5625,
1.03125, 1.08333, 0.9697, 0.9375, 1, 0.94737, 0.89474, 0.93421,
1.07273, 1.04054, 0.98462, 0.95833, 0.95833, 0.8, 0.82759, 2.05882,
1.08333, 0.93333, 1.3, 1.18333, 1, 1.03571, 0.98214, 0.83871,
1.14286, 0.96296, 0.63158, 1, 1.15, 1.15789, 1, 0.94118, 1, 0.95349,
0.85, 0.85, 0.97872, 1, 0.94521, 0.96923, 0.94444, 1.05, 0.8,
1.11111, 1.02439, 0.95238, 0.78947, 1.09524, 0.96429, 0.90476,
1.16667, 0.97059, 1.24194, 1.03846, 0.92857, 1.02174, 1.06349,
1.06897), Angled.Box.H.W.Ratio = c(0.96296, 0.97485, 0.9637,
0.98024, 0.96296, 0.97485, 0.9637, 0.98024, 1, 0.94681, 0.66931,
0.976, 0.97464, 1, 1, 0.93385, 0.94236, 0.92258, 0.85938, 0.92657,
0.40909, 0.78947, 0.85514, 0.93038, 0.97059, 1, 0.80645, 0.64706,
0.83465, 0.69231, 0.88889, 0.81766, 0.93077, 0.94896, 0.97714,
0.90349, 1, 0.98462, 0.9633, 0.77094, 0.77778, 0.6875, 0.96639,
0.85212, 0.93525, 0.97619, 0.97143, 0.9668, 0.86957, 0.85093,
0.96455, 0.99111, 0.92683, 0.95257, 0.94604, 0.81081, 0.9292,
0.92308, 0.8835, 0.78571, 0.78571, 0.94118, 0.97857, 0.93651,
0.92683, 0.93478, 1, 0.67925, 0.89253, 0.98544, 0.99359, 0.87097,
0.99716, 0.97156, 0.65217, 0.88679, 0.92571, 0.769, 0.87778,
0.98557, 0.97735, 0.98137, 1, 0.93333, 0.98745, 0.93822, 0.98897,
0.98813, 0.93822, 0.98897, 0.98813, 0.81962, 0.90323, 0.8, 0.51546,
0.94872, 1, 0.93126, 0.93466, 0.9, 0.94923, 0.6, 0.9557, 0.95426,
0.9802, 0.58893, 0.77273, 0.90556, 0.93333, 0.98649, 0.88462,
0.98626, 0.95346, 0.84809, 0.85, 0.96429, 0.94753, 0.95652, 0.95385,
0.95238, 0.88679, 0.9625, 0.85923, 0.82171, 1, 0.97661, 0.93782,
0.93617, 0.9322, 0.96296, 0.96657, 0.93199, 1, 0.96667, 0.83333,
0.98267, 0.96078, 0.70588, 0.95738, 0.96063, 0.83784, 0.56667,
0.96875, 0.91667, 0.97107, 0.93548, 0.93878, 0.96127, 0.94103,
0.96614, 0.99497, 0.96053, 0.97183, 0.95652, 0.9941, 0.77586,
0.82143, 0.44099, 0.92105, 0.92857, 0.76687, 0.79445, 1, 0.96429,
0.97778, 0.82895, 0.87097, 0.96154, 0.61111, 1, 0.86667, 0.91219,
0.94172, 0.96988, 1, 0.92636, 0.84058, 0.84058, 0.97826, 1, 0.94444,
0.92662, 0.9434, 0.91257, 0.77778, 0.90418, 0.95604, 0.92099,
0.77778, 0.93401, 0.98305, 0.9, 0.85965, 0.91209, 0.78993, 0.55373,
0.99671, 0.97403, 0.93939, 0.95763)), row.names = c(NA, 200L), class = "data.frame")
And this is my code below:
mem.maxVSize(vsize = Inf)
mem.maxNSize(nsize = Inf)
Sys.setenv('R_MAX_VSIZE' = 40000000000000000)
Sys.setenv('R_MAX_NSIZE' = 20000000000000000)
Sys.setenv('R_MAX_MEM_SIZE' = Inf)
rm(list=ls())
gc()
library(dplyr)
row_cf <- function(x, y, df){
sum(df[x,] == df[y,])/ncol(df)
}
data<-read.csv("C:/Users/melanie/Documents/Data/KNNDataCulling.csv", header = TRUE)
data$Particle.Type<-as.factor(data$Particle.Type)
Water<-subset(data, Particle.Type=="WATER")
Water$Particle.Type<-droplevels(Water$Particle.Type)
rm(data)
gc()
Water$Corrected.Diameter.Pixels<-as.numeric(Water$Corrected.Diameter.Pixels)
Water$Contour.Slopes.Focus<-as.numeric(Water$Contour.Slopes.Focus)
Water$Center.Slopes.Focus<-as.numeric(Water$Center.Slopes.Focus)
Water$Hollowness<-as.numeric(Water$Hollowness)
Water$Ellipse.Best.Fit<-as.numeric(Water$Ellipse.Best.Fit)
Water$Ellipse.Minor.Major<-as.numeric(Water$Ellipse.Minor.Major)
Water$Ellipse.Angle<-as.numeric(Water$Ellipse.Angle)
Water$Contour.Circularity<-as.numeric(Water$Contour.Circularity)
Water$Convex.Hull.Circularity<-as.numeric(Water$Convex.Hull.Circularity)
Water$Box.H.W.Ratio<-as.numeric(Water$Box.H.W.Ratio)
Water$Angled.Box.H.W.Ratio<-as.numeric(Water$Angled.Box.H.W.Ratio)
Water <- Water[,-1]
gc()
results <- expand.grid(1:nrow(Water), 1:nrow(Water)) %>%
rename(row_1 = Var1, row_2 = Var2) %>%
rowwise() %>%
mutate(similarity = row_cf(row_1, row_2, Water))
I have increased the memory available and solved the memory errors, but this one remains and I cannot figure out how to solve it, other than running the code on a very small subset of the data, which defeats the purpose).

Is it possible to extend a line with plotly in R?

Yesterday I asked this question about drawing a line that connects two given points using add_lines() from plotly. That makes me think about some other visualization aspects I want to give to my graph: to connect two given points and extend the line across the whole x-axis.
This is my current database:
dput(sma)
structure(list(time = structure(c(1640808000, 1640822400, 1640836800,
1640851200, 1640865600, 1640880000, 1640894400, 1640908800, 1640923200,
1640937600, 1640952000, 1640966400, 1640980800, 1640995200, 1641009600,
1641024000, 1641038400, 1641052800, 1641067200, 1641081600, 1641096000,
1641110400, 1641124800, 1641139200, 1641153600, 1641168000, 1641182400,
1641196800, 1641211200, 1641225600, 1641240000, 1641254400, 1641268800,
1641283200, 1641297600, 1641312000, 1641326400, 1641340800, 1641355200,
1641369600, 1641384000, 1641398400, 1641412800, 1641427200, 1641441600,
1641456000, 1641470400, 1641484800, 1641499200, 1641513600, 1641528000,
1641542400, 1641556800, 1641571200, 1641585600, 1641600000, 1641614400,
1641628800, 1641643200, 1641657600, 1641672000, 1641686400, 1641700800,
1641715200, 1641729600, 1641744000, 1641758400, 1641772800, 1641787200,
1641801600, 1641816000, 1641830400, 1641844800, 1641859200, 1641873600,
1641888000, 1641902400, 1641916800, 1641931200, 1641945600, 1641960000,
1641974400, 1641988800, 1642003200, 1642017600, 1642032000, 1642046400,
1642060800, 1642075200, 1642089600, 1642104000, 1642118400, 1642132800,
1642147200, 1642161600, 1642176000, 1642190400, 1642204800, 1642219200,
1642233600, 1642248000, 1642262400, 1642276800, 1642291200, 1642305600,
1642320000, 1642334400, 1642348800, 1642363200, 1642377600, 1642392000,
1642406400, 1642420800, 1642435200, 1642449600, 1642464000, 1642478400,
1642492800, 1642507200, 1642521600, 1642536000, 1642550400, 1642564800,
1642579200, 1642593600, 1642608000, 1642622400, 1642636800, 1642651200,
1642665600, 1642680000, 1642694400, 1642708800, 1642723200, 1642737600,
1642752000, 1642766400, 1642780800, 1642795200, 1642809600, 1642824000,
1642838400, 1642852800, 1642867200, 1642881600, 1642896000, 1642910400,
1642924800, 1642939200, 1642953600, 1642968000, 1642982400, 1642996800,
1643011200, 1643025600, 1643040000, 1643054400, 1643068800, 1643083200,
1643097600, 1643112000, 1643126400, 1643140800, 1643155200, 1643169600,
1643184000, 1643198400, 1643212800, 1643227200, 1643241600, 1643256000,
1643270400, 1643284800, 1643299200, 1643313600, 1643328000, 1643342400,
1643356800, 1643371200, 1643385600, 1643400000, 1643414400, 1643428800,
1643443200, 1643457600, 1643472000, 1643486400, 1643500800, 1643515200,
1643529600, 1643544000, 1643558400, 1643572800, 1643587200, 1643601600,
1643616000, 1643630400, 1643644800, 1643659200, 1643673600, 1643688000,
1643702400, 1643716800, 1643731200, 1643745600, 1643760000, 1643774400,
1643788800, 1643803200, 1643817600, 1643832000, 1643846400, 1643860800,
1643875200, 1643889600, 1643904000, 1643918400, 1643932800, 1643947200,
1643961600, 1643976000, 1643990400, 1644004800, 1644019200, 1644033600
), class = c("POSIXct", "POSIXt"), tzone = ""), open = c(0.12428,
0.12167, 0.11791, 0.12133, 0.124, 0.12245, 0.12375, 0.12392,
0.12379, 0.12166, 0.1239, 0.12416, 0.11915, 0.12107, 0.12243,
0.12321, 0.12216, 0.12488, 0.12839, 0.12815, 0.12759, 0.12704,
0.12746, 0.12669, 0.12634, 0.12571, 0.12455, 0.12455, 0.12861,
0.12556, 0.12244, 0.12281, 0.12175, 0.12213, 0.12338, 0.12431,
0.12216, 0.1217, 0.12407, 0.12479, 0.12338, 0.12365, 0.11492,
0.11013, 0.10664, 0.10831, 0.10642, 0.10901, 0.10986, 0.10979,
0.10398, 0.1033, 0.104, 0.10127, 0.10275, 0.10207, 0.10357, 0.10443,
0.10514, 0.10271, 0.09677, 0.10175, 0.10111, 0.10103, 0.10221,
0.10152, 0.10517, 0.10355, 0.10461, 0.10576, 0.10419, 0.09702,
0.09658, 0.09847, 0.10165, 0.10064, 0.0999, 0.10119, 0.10199,
0.10152, 0.10233, 0.10215, 0.10273, 0.1059, 0.10571, 0.10564,
0.10405, 0.10608, 0.10475, 0.10286, 0.10122, 0.10018, 0.10022,
0.10127, 0.09859, 0.10011, 0.10054, 0.10066, 0.10147, 0.10333,
0.10762, 0.11317, 0.11409, 0.11525, 0.11243, 0.11022, 0.10932,
0.11007, 0.10968, 0.11175, 0.11387, 0.11404, 0.11295, 0.10842,
0.10746, 0.10779, 0.11022, 0.11553, 0.11481, 0.11341, 0.1146,
0.11565, 0.11529, 0.11192, 0.11229, 0.11194, 0.11081, 0.10661,
0.10554, 0.10666, 0.10636, 0.10864, 0.10741, 0.09956, 0.09362,
0.09521, 0.09495, 0.0936, 0.09223, 0.08409, 0.0828, 0.07273,
0.07066, 0.07008, 0.0701, 0.072, 0.0711, 0.07424, 0.07467, 0.07324,
0.07124, 0.07559, 0.07096, 0.06866, 0.06469, 0.06602, 0.06853,
0.07014, 0.06903, 0.06895, 0.07152, 0.0715, 0.07204, 0.07213,
0.07263, 0.07346, 0.07471, 0.07629, 0.0757, 0.07368, 0.07013,
0.07135, 0.07329, 0.07601, 0.07396, 0.07423, 0.07524, 0.074,
0.0731, 0.0754, 0.07527, 0.07648, 0.07666, 0.07782, 0.07804,
0.07598, 0.07785, 0.07924, 0.07924, 0.0803, 0.07938, 0.07773,
0.07475, 0.07529, 0.07172, 0.07102, 0.07118, 0.07292, 0.07386,
0.07367, 0.07504, 0.07506, 0.07524, 0.0764, 0.07571, 0.07642,
0.07676, 0.07632, 0.0777, 0.07355, 0.07462, 0.07218, 0.07176,
0.07262, 0.07203, 0.07313, 0.0723, 0.07433, 0.075, 0.07626, 0.07713,
0.07766, 0.07823, 0.07916, 0.08149), high = c(0.1249, 0.1219,
0.1221, 0.12449, 0.12468, 0.12469, 0.125, 0.12459, 0.12419, 0.12509,
0.1247, 0.12435, 0.12219, 0.12314, 0.12337, 0.12379, 0.1257,
0.13202, 0.12864, 0.12884, 0.12778, 0.12824, 0.1275, 0.12846,
0.12643, 0.12586, 0.12611, 0.1293, 0.1291, 0.12598, 0.12539,
0.12323, 0.12241, 0.1235, 0.1258, 0.12597, 0.1243, 0.12522, 0.12494,
0.12527, 0.1252, 0.12372, 0.11609, 0.11294, 0.10881, 0.10838,
0.11043, 0.11073, 0.1107, 0.11156, 0.1046, 0.10593, 0.10532,
0.10439, 0.10434, 0.10447, 0.10498, 0.10556, 0.10518, 0.1035,
0.10294, 0.10226, 0.10237, 0.10302, 0.10435, 0.10577, 0.10697,
0.10637, 0.10794, 0.10592, 0.10451, 0.10002, 0.09904, 0.10209,
0.10208, 0.10162, 0.10222, 0.10529, 0.10228, 0.10552, 0.10301,
0.10383, 0.10751, 0.10666, 0.10712, 0.10641, 0.10727, 0.10798,
0.10733, 0.10371, 0.10179, 0.10146, 0.10257, 0.10128, 0.10085,
0.10155, 0.10168, 0.10219, 0.1042, 0.1084, 0.11577, 0.115, 0.11817,
0.116, 0.1129, 0.11084, 0.11083, 0.1113, 0.11353, 0.11784, 0.11776,
0.11845, 0.11295, 0.10911, 0.10845, 0.11478, 0.11579, 0.1175,
0.11665, 0.11785, 0.11698, 0.1194, 0.11767, 0.11323, 0.11335,
0.11267, 0.11098, 0.10751, 0.10698, 0.10684, 0.10928, 0.1089,
0.10764, 0.10056, 0.09559, 0.09648, 0.09531, 0.0943, 0.09277,
0.08542, 0.08315, 0.07432, 0.07523, 0.07335, 0.07358, 0.07323,
0.07433, 0.07611, 0.07517, 0.07387, 0.07573, 0.07559, 0.0712,
0.0701, 0.0662, 0.06954, 0.07125, 0.07021, 0.06932, 0.07309,
0.073, 0.0732, 0.07273, 0.07317, 0.074, 0.07531, 0.07681, 0.07934,
0.0757, 0.07448, 0.07179, 0.07405, 0.07721, 0.0763, 0.07491,
0.07546, 0.07561, 0.07502, 0.07573, 0.07638, 0.0769, 0.07732,
0.078, 0.07849, 0.07858, 0.07817, 0.07933, 0.08047, 0.08092,
0.0805, 0.07974, 0.07813, 0.0763, 0.07558, 0.07249, 0.07182,
0.07319, 0.0752, 0.07437, 0.07518, 0.07607, 0.07724, 0.07668,
0.07748, 0.07744, 0.07743, 0.07725, 0.07776, 0.07836, 0.07492,
0.07462, 0.07259, 0.07278, 0.07301, 0.07326, 0.0739, 0.07444,
0.07535, 0.07669, 0.07729, 0.07824, 0.07928, 0.07934, 0.08162,
0.08316), low = c(0.11978, 0.1178, 0.1172, 0.1201, 0.12178, 0.12205,
0.12212, 0.12193, 0.12048, 0.12058, 0.12257, 0.11896, 0.11811,
0.12107, 0.12117, 0.12129, 0.122, 0.12429, 0.1266, 0.12721, 0.1266,
0.12661, 0.12412, 0.12504, 0.12548, 0.12404, 0.1243, 0.12431,
0.12533, 0.12138, 0.12, 0.12036, 0.12059, 0.12162, 0.12222, 0.1203,
0.12148, 0.12103, 0.12313, 0.12225, 0.12175, 0.11411, 0.10467,
0.10653, 0.10525, 0.10507, 0.10529, 0.10833, 0.10878, 0.10316,
0.10021, 0.10294, 0.09925, 0.10017, 0.1003, 0.10126, 0.10326,
0.10373, 0.10133, 0.09563, 0.09632, 0.09935, 0.10089, 0.09973,
0.10072, 0.10144, 0.10297, 0.10316, 0.10421, 0.10231, 0.09465,
0.09572, 0.09618, 0.09773, 0.09974, 0.09863, 0.09931, 0.10089,
0.10076, 0.10128, 0.10143, 0.10196, 0.10253, 0.10498, 0.1053,
0.10303, 0.10376, 0.10452, 0.10154, 0.10024, 0.0996, 0.09903,
0.1002, 0.09738, 0.09778, 0.09941, 0.1003, 0.10007, 0.10095,
0.1027, 0.10753, 0.11202, 0.11312, 0.1108, 0.1097, 0.10787, 0.10805,
0.10945, 0.10915, 0.10955, 0.11154, 0.11255, 0.10815, 0.10594,
0.10556, 0.10715, 0.10988, 0.11185, 0.11061, 0.11198, 0.11243,
0.11368, 0.11125, 0.10968, 0.11047, 0.11069, 0.10627, 0.10495,
0.10497, 0.10559, 0.10482, 0.10695, 0.099, 0.09241, 0.09346,
0.09452, 0.08974, 0.09206, 0.08209, 0.08185, 0.07179, 0.06451,
0.06982, 0.06912, 0.06969, 0.06978, 0.07074, 0.07367, 0.07129,
0.07085, 0.071, 0.07051, 0.06847, 0.06405, 0.06267, 0.0644, 0.06819,
0.06828, 0.06762, 0.06881, 0.07029, 0.07149, 0.07066, 0.07069,
0.07232, 0.07344, 0.07382, 0.07435, 0.07163, 0.0697, 0.0698,
0.07053, 0.07294, 0.07338, 0.07073, 0.07214, 0.07394, 0.07241,
0.07208, 0.07436, 0.0751, 0.0757, 0.07623, 0.07703, 0.07535,
0.07524, 0.0776, 0.07782, 0.07924, 0.0789, 0.07693, 0.07389,
0.07411, 0.07132, 0.07025, 0.07026, 0.07008, 0.07264, 0.07324,
0.07341, 0.07425, 0.07435, 0.07507, 0.07561, 0.07569, 0.07585,
0.07574, 0.07585, 0.07335, 0.0722, 0.07157, 0.071, 0.0716, 0.07029,
0.07111, 0.07195, 0.07201, 0.07392, 0.07465, 0.07623, 0.07472,
0.0775, 0.07763, 0.07878, 0.08125), close = c(0.12167, 0.11791,
0.12137, 0.124, 0.12236, 0.12377, 0.12392, 0.12381, 0.12164,
0.12389, 0.12415, 0.11915, 0.12109, 0.1224, 0.1232, 0.12214,
0.12488, 0.12839, 0.1281, 0.12755, 0.12701, 0.12745, 0.12667,
0.12633, 0.12575, 0.12454, 0.12458, 0.12859, 0.12555, 0.1224,
0.12279, 0.12176, 0.12208, 0.12335, 0.12427, 0.12214, 0.1217,
0.12403, 0.12473, 0.12335, 0.1237, 0.11486, 0.11016, 0.10653,
0.10829, 0.10642, 0.10902, 0.10982, 0.10981, 0.10402, 0.10336,
0.104, 0.10134, 0.10268, 0.10199, 0.10358, 0.10443, 0.10513,
0.10274, 0.09678, 0.10175, 0.10115, 0.10107, 0.1022, 0.10152,
0.10517, 0.10362, 0.10465, 0.10576, 0.10422, 0.09695, 0.09657,
0.09841, 0.10165, 0.10065, 0.09993, 0.10115, 0.10199, 0.10155,
0.10233, 0.10212, 0.10274, 0.10594, 0.10571, 0.10572, 0.10405,
0.10609, 0.10478, 0.10286, 0.10132, 0.10018, 0.10025, 0.10122,
0.09857, 0.10011, 0.10051, 0.10072, 0.10155, 0.10333, 0.10762,
0.11307, 0.11414, 0.11527, 0.11241, 0.11021, 0.1093, 0.11005,
0.10972, 0.11176, 0.11385, 0.11405, 0.1129, 0.10851, 0.10746,
0.10777, 0.11022, 0.11558, 0.11485, 0.11349, 0.11465, 0.11569,
0.11527, 0.1119, 0.11233, 0.11197, 0.11084, 0.10661, 0.10556,
0.10664, 0.1064, 0.10863, 0.10743, 0.09959, 0.09358, 0.09525,
0.09484, 0.09361, 0.09215, 0.08424, 0.08281, 0.0727, 0.0706,
0.07001, 0.07005, 0.07199, 0.07117, 0.07421, 0.07469, 0.07327,
0.07132, 0.07559, 0.07097, 0.06862, 0.0647, 0.066, 0.06857, 0.07012,
0.06901, 0.06896, 0.0715, 0.07156, 0.07209, 0.07207, 0.07261,
0.07345, 0.07469, 0.07625, 0.0758, 0.07376, 0.07006, 0.07137,
0.07336, 0.07602, 0.07389, 0.07429, 0.0752, 0.07399, 0.07305,
0.07533, 0.07525, 0.0765, 0.07666, 0.07782, 0.07804, 0.07596,
0.07783, 0.07925, 0.07921, 0.08028, 0.07938, 0.0779, 0.07477,
0.07534, 0.07174, 0.07103, 0.07122, 0.07289, 0.07387, 0.07369,
0.07503, 0.07509, 0.07524, 0.07636, 0.07573, 0.07639, 0.07679,
0.07628, 0.0777, 0.07359, 0.07462, 0.07216, 0.07173, 0.07265,
0.07201, 0.07315, 0.07227, 0.07429, 0.07499, 0.07626, 0.07713,
0.07766, 0.07819, 0.07915, 0.08148, 0.08275), volume = c(17894295,
25956559, 19646834, 21073444, 18817421, 12316289, 11348380, 14945318,
20611382, 29389056, 15639183, 23990903, 10230550, 11791876, 8849962,
8712513, 17411436, 52294930, 13741243, 12159456, 10156693, 7392933,
24556017, 12498171, 6585602, 9053311, 10389994, 32763165, 18691599,
20920341, 17194082, 13384844, 10762647, 11238837, 20643490, 17826487,
8605881, 12725146, 8033532, 14576577, 18203767, 33106274, 57475480,
35090353, 19236551, 22848525, 19670114, 12209910, 9189784, 28139942,
32849205, 23256020, 31210609, 23094329, 12240627, 12774399, 8347728,
10614794, 13157648, 47509634, 20708007, 13009872, 5347605, 10099313,
18566517, 24284140, 16257416, 13504669, 26353561, 13722621, 42173001,
23675661, 8144656, 17929342, 9387011, 13854189, 14603858, 31616737,
6704224, 24196867, 13695017, 11613987, 27856536, 13454585, 10497017,
16458068, 16297639, 12785798, 19360445, 12732714, 10444114, 16201247,
9645137, 19007416, 14556473, 9980469, 8106055, 13820499, 10194965,
64253247, 161980227, 55008265, 62794334, 47634737, 27375292,
28948205, 23303586, 15667935, 20378324, 42039932, 45234586, 55979026,
38458874, 19968558, 11843244, 33406862, 42373158, 54126294, 46806385,
61654732, 27197944, 59155494, 33707242, 23832047, 19967177, 10957640,
15637922, 19658790, 13028772, 9082828, 24976755, 10789730, 39076951,
49842677, 16384967, 15601195, 29659625, 14836814, 53131858, 26904846,
50215911, 80446251, 31711637, 27684325, 18295756, 30244578, 25000228,
31701319, 20297596, 17620148, 16712144, 24532847, 20024178, 61355138,
49383309, 34613954, 15938600, 14048986, 9165050, 33670464, 28771619,
24220858, 11889148, 24206767, 16696844, 19341205, 30682562, 48411541,
31624605, 19583695, 7736058, 14697691, 20371228, 21601985, 14667855,
11662673, 8565838, 8950674, 15198713, 18115403, 13873815, 9454750,
13116891, 11227183, 17723342, 11168569, 17650051, 16902150, 16042595,
12631966, 17581570, 22259046, 16421002, 23295568, 15918092, 18004724,
24079621, 23097753, 12800081, 12312440, 13131810, 19374725, 14036774,
15552921, 12017393, 6465640, 6071254, 8288237, 23909383, 15594514,
13318570, 9361610, 7166725, 9715764, 8906698, 8078021, 8742947,
5312715, 8228518, 7468992, 21681712, 15425063, 9088154, 16051149,
14306452), trades = c(11591L, 13904L, 8770L, 8976L, 8889L, 7218L,
7956L, 10289L, 8338L, 15267L, 7974L, 11350L, 6627L, 8199L, 5462L,
5711L, 9750L, 27559L, 7345L, 7275L, 4761L, 4086L, 11405L, 7343L,
3511L, 5410L, 4619L, 14885L, 10363L, 11337L, 10040L, 7900L, 6029L,
6823L, 9894L, 9795L, 5252L, 8359L, 4739L, 8325L, 10895L, 17994L,
26704L, 16954L, 11073L, 11451L, 10072L, 6270L, 4694L, 13397L,
14960L, 9414L, 14906L, 12126L, 6198L, 5929L, 4447L, 4968L, 6663L,
19502L, 8574L, 6111L, 2793L, 4580L, 7616L, 11026L, 7975L, 6380L,
10178L, 7006L, 18590L, 11151L, 4108L, 7542L, 4110L, 7336L, 7791L,
14672L, 3764L, 12346L, 6006L, 6644L, 14171L, 6804L, 5282L, 7091L,
6975L, 7109L, 9196L, 7046L, 5131L, 7664L, 5566L, 9995L, 8029L,
4665L, 3391L, 5387L, 5661L, 21898L, 63727L, 23335L, 25023L, 22152L,
11598L, 12217L, 10815L, 6903L, 10246L, 25837L, 21694L, 21720L,
12474L, 8370L, 5376L, 15747L, 18057L, 20906L, 17232L, 25948L,
11954L, 24800L, 12686L, 9503L, 8451L, 6271L, 8233L, 10329L, 6095L,
5637L, 9733L, 6092L, 13746L, 19684L, 7050L, 6934L, 13457L, 7401L,
17572L, 11348L, 18615L, 25756L, 10412L, 10349L, 6128L, 12691L,
9583L, 10143L, 7123L, 7471L, 6147L, 10867L, 6986L, 14811L, 15151L,
9144L, 4273L, 4538L, 3426L, 9159L, 9095L, 8463L, 4558L, 7123L,
6183L, 6101L, 8886L, 16735L, 8368L, 6808L, 3165L, 5547L, 8119L,
9066L, 6105L, 5640L, 4008L, 4116L, 4971L, 6974L, 4911L, 3472L,
4044L, 4096L, 5997L, 4972L, 7099L, 7793L, 6059L, 4567L, 5282L,
6897L, 6491L, 10157L, 6830L, 6899L, 8623L, 9719L, 4053L, 4742L,
4628L, 7551L, 5978L, 7164L, 4851L, 3556L, 3060L, 3858L, 8498L,
6731L, 5812L, 3765L, 2530L, 3805L, 3734L, 4060L, 3785L, 2778L,
4578L, 4151L, 8128L, 7304L, 3698L, 7376L, 5582L), SMA_5 = c(NA,
NA, NA, NA, 0.121462, 0.121882, 0.123084, 0.123572, 0.1231, 0.123406,
0.123482, 0.122528, 0.121984, 0.122136, 0.121998, 0.121596, 0.122742,
0.124202, 0.125342, 0.126212, 0.127186, 0.1277, 0.127356, 0.127002,
0.126642, 0.126148, 0.125574, 0.125958, 0.125802, 0.125132, 0.124782,
0.124218, 0.122916, 0.122476, 0.12285, 0.12272, 0.122708, 0.123098,
0.123374, 0.12319, 0.123502, 0.122134, 0.11936, 0.11572, 0.112708,
0.109252, 0.108084, 0.108016, 0.108672, 0.107818, 0.107206, 0.106202,
0.104506, 0.10308, 0.102674, 0.102718, 0.102804, 0.103562, 0.103574,
0.102532, 0.102166, 0.10151, 0.100698, 0.10059, 0.101538, 0.102222,
0.102716, 0.103432, 0.104144, 0.104684, 0.10304, 0.10163, 0.100382,
0.09956, 0.098846, 0.099442, 0.100358, 0.101074, 0.101054, 0.10139,
0.101828, 0.102146, 0.102936, 0.103768, 0.104446, 0.104832, 0.105502,
0.10527, 0.1047, 0.10382, 0.103046, 0.101878, 0.101166, 0.100308,
0.100066, 0.100132, 0.100226, 0.100292, 0.101244, 0.102746, 0.105258,
0.107942, 0.110686, 0.112502, 0.11302, 0.112266, 0.111448, 0.110338,
0.110208, 0.110936, 0.111886, 0.112456, 0.112214, 0.111354, 0.110138,
0.109372, 0.109908, 0.111176, 0.112382, 0.113758, 0.114852, 0.11479,
0.1142, 0.113968, 0.113432, 0.112462, 0.11073, 0.109462, 0.108324,
0.10721, 0.106768, 0.106932, 0.105738, 0.103126, 0.100896, 0.098138,
0.095374, 0.093886, 0.092018, 0.08953, 0.085102, 0.0805, 0.076072,
0.073234, 0.07107, 0.070764, 0.071486, 0.072422, 0.073066, 0.072932,
0.073816, 0.073168, 0.071954, 0.07024, 0.069176, 0.067772, 0.067602,
0.06768, 0.068532, 0.069632, 0.07023, 0.070624, 0.071236, 0.071966,
0.072356, 0.072982, 0.073814, 0.07456, 0.07479, 0.074112, 0.073448,
0.07287, 0.072914, 0.07294, 0.073786, 0.074552, 0.074678, 0.074084,
0.074372, 0.074564, 0.074824, 0.075358, 0.076312, 0.076854, 0.076996,
0.077262, 0.07778, 0.078058, 0.078506, 0.07919, 0.079204, 0.078308,
0.077534, 0.075826, 0.074156, 0.07282, 0.072444, 0.07215, 0.07254,
0.07334, 0.074114, 0.074584, 0.075082, 0.07549, 0.075762, 0.076102,
0.07631, 0.076578, 0.07615, 0.075796, 0.07487, 0.07396, 0.07295,
0.072634, 0.07234, 0.072362, 0.072874, 0.073342, 0.074192, 0.074988,
0.076066, 0.076846, 0.077678, 0.078722, 0.079846), SMA_10 = c(NA,
NA, NA, NA, NA, NA, NA, NA, NA, 0.122434, 0.122682, 0.122806,
0.122778, 0.122618, 0.122702, 0.122539, 0.122635, 0.123093, 0.123739,
0.124105, 0.124391, 0.125221, 0.125779, 0.126172, 0.126427, 0.126667,
0.126637, 0.126657, 0.126402, 0.125887, 0.125465, 0.124896, 0.124437,
0.124139, 0.123991, 0.123751, 0.123463, 0.123007, 0.122925, 0.12302,
0.123111, 0.122421, 0.121229, 0.119547, 0.117949, 0.116377, 0.115109,
0.113688, 0.112196, 0.110263, 0.108229, 0.107143, 0.106261, 0.105876,
0.105246, 0.104962, 0.104503, 0.104034, 0.103327, 0.102603, 0.102442,
0.102157, 0.10213, 0.102082, 0.102035, 0.102194, 0.102113, 0.102065,
0.102367, 0.103111, 0.102631, 0.102173, 0.101907, 0.101852, 0.101765,
0.101241, 0.100994, 0.100728, 0.100307, 0.100118, 0.100635, 0.101252,
0.102005, 0.102411, 0.102918, 0.10333, 0.103824, 0.104103, 0.104234,
0.104133, 0.103939, 0.10369, 0.103218, 0.102504, 0.101943, 0.101589,
0.101052, 0.100729, 0.100776, 0.101406, 0.102695, 0.104084, 0.105489,
0.106873, 0.107883, 0.108762, 0.109695, 0.110512, 0.111355, 0.111978,
0.112076, 0.111952, 0.111276, 0.110781, 0.110537, 0.110629, 0.111182,
0.111695, 0.111868, 0.111948, 0.112112, 0.112349, 0.112688, 0.113175,
0.113595, 0.113657, 0.11276, 0.111831, 0.111146, 0.110321, 0.109615,
0.108831, 0.1076, 0.105725, 0.104053, 0.102453, 0.101153, 0.099812,
0.097572, 0.095213, 0.09162, 0.087937, 0.084979, 0.082626, 0.0803,
0.077933, 0.075993, 0.074247, 0.07315, 0.072001, 0.07229, 0.072327,
0.072188, 0.071653, 0.071054, 0.070794, 0.070385, 0.069817, 0.069386,
0.069404, 0.069001, 0.069113, 0.069458, 0.070249, 0.070994, 0.071606,
0.072219, 0.072898, 0.073378, 0.073234, 0.073215, 0.073342, 0.073737,
0.073865, 0.073949, 0.074, 0.073774, 0.073499, 0.073656, 0.074175,
0.074688, 0.075018, 0.075198, 0.075613, 0.07578, 0.076043, 0.076569,
0.077185, 0.07768, 0.078093, 0.078233, 0.078044, 0.077796, 0.077166,
0.076673, 0.076012, 0.075376, 0.074842, 0.074183, 0.073748, 0.073467,
0.073514, 0.073616, 0.074015, 0.074551, 0.075108, 0.075447, 0.07583,
0.07582, 0.075779, 0.075486, 0.075135, 0.074764, 0.074392, 0.074068,
0.073616, 0.073417, 0.073146, 0.073413, 0.073664, 0.074214, 0.07486,
0.07551, 0.076457, 0.077417), SMA_20 = c(NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.1232695,
0.1235365, 0.1240135, 0.1242785, 0.124395, 0.1245645, 0.124603,
0.124636, 0.124875, 0.1250705, 0.124996, 0.124928, 0.1250585,
0.125108, 0.1251555, 0.125209, 0.125209, 0.12505, 0.124832, 0.1246635,
0.1244535, 0.124288, 0.1236585, 0.122833, 0.121843, 0.12097,
0.120064, 0.119286, 0.1183475, 0.1175605, 0.1166415, 0.11567,
0.114782, 0.113745, 0.1127115, 0.1115975, 0.1106695, 0.109806,
0.108861, 0.1077615, 0.106433, 0.1053355, 0.10465, 0.1041955,
0.103979, 0.1036405, 0.103578, 0.103308, 0.1030495, 0.102847,
0.102857, 0.1025365, 0.102165, 0.1020185, 0.101967, 0.1019, 0.1017175,
0.1015535, 0.1013965, 0.101337, 0.1016145, 0.101633, 0.1017125,
0.101956, 0.1021315, 0.1023415, 0.1022855, 0.102409, 0.1024155,
0.1022705, 0.1021255, 0.102287, 0.102471, 0.1026115, 0.1024575,
0.1024305, 0.1024595, 0.102438, 0.102416, 0.102505, 0.1027695,
0.103317, 0.103887, 0.1043535, 0.1046885, 0.104913, 0.1051755,
0.1053735, 0.1056205, 0.1060655, 0.106692, 0.1073855, 0.108018,
0.1083825, 0.108827, 0.10921, 0.1096955, 0.1104385, 0.1111035,
0.1116115, 0.111963, 0.112094, 0.1121505, 0.111982, 0.111978,
0.112066, 0.112143, 0.111971, 0.111763, 0.111507, 0.1111345,
0.1108635, 0.11059, 0.110144, 0.10945, 0.108824, 0.108055, 0.1069565,
0.1058215, 0.104359, 0.102767, 0.1006175, 0.0983839999999999,
0.0962894999999999, 0.0941754999999999, 0.0921764999999999, 0.0901929999999999,
0.0885729999999999, 0.0870294999999999, 0.0853609999999999, 0.0836069999999999,
0.0819549999999999, 0.0801319999999999, 0.0785834999999999, 0.0771394999999999,
0.0756769999999999, 0.0743634999999999, 0.0731889999999999, 0.0720319999999999,
0.0712679999999999, 0.0707024999999999, 0.0706454999999999, 0.0707199999999999,
0.0708229999999999, 0.0709509999999999, 0.0710239999999999, 0.0711999999999999,
0.0713019999999999, 0.0713574999999999, 0.0713819999999999, 0.0713189999999999,
0.0711079999999999, 0.0712274999999999, 0.0715974999999999, 0.0720569999999999,
0.0724714999999999, 0.0728029999999999, 0.0729964999999999, 0.0731984999999999,
0.0735169999999999, 0.0737044999999999, 0.0739514999999999, 0.0741799999999999,
0.0744674999999999, 0.0747389999999999, 0.0748644999999999, 0.0750214999999999,
0.0751714999999999, 0.0753419999999999, 0.0756679999999999, 0.0761339999999999,
0.0764604999999999, 0.0765309999999999, 0.0764969999999999, 0.0763894999999999,
0.0762264999999999, 0.0760274999999999, 0.0759724999999999, 0.0760134999999999,
0.0759314999999999, 0.0759204999999999, 0.0758499999999999, 0.0757789999999999,
0.0757059999999999, 0.0755904999999999, 0.0756119999999999, 0.0755599999999999,
0.0754114999999999, 0.0753359999999999, 0.0750014999999999, 0.0747634999999999,
0.0744764999999999, 0.0743244999999999, 0.0741899999999999, 0.0742034999999999,
0.0743094999999999, 0.0743619999999999, 0.0744319999999999, 0.0744879999999999,
0.0746164999999999, 0.0747214999999999, 0.0748499999999999, 0.0749974999999999,
0.0751369999999999, 0.0754244999999999, 0.0757424999999999)), row.names = c(NA,
-225L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x00000000105f1ef0>)
What I want is to connect the two highest highs and expand the line across all the x-axis. Here's the code to get that data:
highs <- arrange(sma, desc(high))%>%
slice(1:2)
highs
time open high low close volume trades SMA_5 SMA_10 SMA_20
1: 2022-01-01 10:00:00 0.12488 0.13202 0.12429 0.12839 52294930 27559 0.124202 0.123093 NA
2: 2022-01-03 02:00:00 0.12455 0.12930 0.12431 0.12859 32763165 14885 0.125958 0.126657 0.124875
So basically I have 0.13202 from January 1st and 0.12930 from January 3rd as my highest highs. With some code such as:
add_lines(inherit = F, data = highs, x = ~time, y = ~high,
name = "Higher highs trendline", line = list(color = "seagreen", width = 2.5, dash = "dot"))
I can draw the line exactly for the two points in my highs object. But what I want is that this line goes across all my graph. In short, given two points I want to draw a trendline the same way we used to do on basic algebra. Main code for my graph is:
sma %>% plot_ly(x = ~time, type="candlestick",
open = ~open, close = ~close,
high = ~high, low = ~low) %>%
add_lines(x = ~time, y= ~SMA_5, line = list(color = "gold", width = 2), inherit = F,
name = "SMA 5", showlegend=T)%>%
add_lines(x = ~time, y= ~SMA_10, line = list(color = "deeppink", width = 2), inherit = F,
name = "SMA 10", showlegend=T)%>%
add_lines(x = ~time, y= ~SMA_20, line = list(color = "purple", width = 2), inherit = F,
name = "SMA 20", showlegend=T)%>%
plotly::layout(title = paste0(nombre, " Simple Moving Average, ", tiempo),
xaxis= list(title="Time", rangeslider = list(visible = F)), yaxis = list(title = "Price"),
sliders=list(visible=F)) -> sma_
Any help and orientation will be much appreciated.
You could fit a linear model on the two high points, and predict it's values on the remaining dataset:
fit <- lm(high ~ time, data = highs)
sma %>% plot_ly(x = ~time, type="candlestick",
open = ~open, close = ~close,
high = ~high, low = ~low) %>%
add_lines( x = ~time, y = ~predict(fit,sma))

R: Error when plotting a normal to compare with my data distribution

I have the following vector called Datadiff:
[1] 0.00000 -0.01415 2.68350 -4.26980 -2.28975 -1.27000 6.63400 -3.13965 -1.67050 -0.28920 -0.42435
[12] -1.36785 -1.97000 6.62200 -0.82470 -1.99530 1.84275 -4.70575 3.67150 -1.00900 -1.00205 -0.77350
[23] -0.86150 -2.12430 2.20255 2.03850 -0.19295 1.83205 2.04300 -3.51635 -3.32000 9.07800 -0.60280
[34] 11.15045 -8.44820 -9.49590 0.13885 -1.06000 3.85800 -1.27255 0.35010 3.38085 -5.70870 5.08605
[45] -6.67000 6.57600 -4.48095 0.05825 3.35215 5.94525 -8.91095 -1.21000 7.99800 -2.21730 13.66610
[56] -20.52355 0.68220 3.64315 -0.46000 4.08800 5.76705 3.88775 -12.32920 -0.08525 -4.10745 -6.70000
[67] 8.73800 5.17880 -8.20225 -1.61770 23.66225 -16.23860 -2.25000 -5.24400 8.21195 19.02100 -1.55330
[78] -10.74680 -13.19870 4.32000 -3.45600 0.29670 2.22515 -1.77935 -0.26525 0.32630 0.37000 10.26200
[89] 5.38240 -15.50855 -0.65105 6.84655 -9.38970 1.70000 5.43200 10.17880 2.98075 -10.85725 -6.22135
[100] -1.89010 -3.46000 -2.29000 4.69180 1.20210 -0.95415 -3.40435 -7.49000 -0.15000 7.49445 -0.14045
[111] 3.35195 -2.63695 0.83655 -12.01000 11.16400 9.18425 -3.91240 6.02935 -2.27235 -4.32110 -3.16000
[122] 1.17000 0.74640 -0.12670 2.26105 0.04115 -2.31855 -2.30000 1.81400 0.68420 -0.94390 0.67445
[133] 7.34260 -8.99235 -3.63000 4.55800 5.04180 -5.30290 0.96565 2.37130 0.33100 -2.53000 6.50400
[144] 2.81535 -0.90240 -2.62860 -3.69285 0.61605 -5.81000 5.32800 -0.39985 0.52635 0.39335 0.56145
[155] -0.92660 -1.53000 10.51400 -3.33635 -4.52020 -1.85500 0.36355 -11.26815 1.62000 10.89000 -0.51330
[166] -9.56000 -1.79115 -14.12515 14.49105 -6.90000 2.76400 19.79725 -1.36595 -5.14430 1.67195 -9.18290
[177] -3.72000 18.14200 -2.22105 -5.47200 -1.74350 7.38740 -2.16620 -12.96000 12.10000 1.05790 4.37990
[188] 1.46360 -1.55485 -5.30650 -3.08000 9.59000 -0.70365 -0.29480 0.08570 -3.14220 -4.90170 -4.05690
[199] 0.82470 -0.61950 0.58260 -8.70000 16.49600 -2.05375 -1.15520 0.74145 0.49035 -9.79180 -1.06000
[210] 9.70800 -2.02660 -0.83785 1.14500 -1.46245 -4.42830 -16.34000 18.55000 1.93415 -3.23050 -3.63245
[221] 7.33200 -5.96870 -0.93000 2.03600 5.73760 -2.35745 5.82470 -2.38335 -5.71340 -7.60000 15.42000
[232] -1.36575 -1.38560 -5.07790 5.94480 -10.58400 -4.41000 11.21400 0.33840 1.42130 -3.75035 7.43265
[243] 2.78635 -15.19000 -1.36800 16.65735 -3.12405 -2.51290 3.51920 -9.63090 -0.95000 21.88000 -6.28715
[254] 6.66370 0.89995 -3.76125 -10.85840 -3.51000 13.74800 -3.02445 0.29100 0.33760 0.13705 -7.97660
[265] -1.15000 6.79400 -3.98745 -1.46300 2.38375 1.73950 -10.64685 -7.78000 15.32400 2.30850 -2.49665
[276] -2.86120 -1.30305 -2.09495 -2.23000 11.44800 -0.74900 0.83135 -3.44695 0.31755 -4.00500 -8.25000
[287] 16.45800 3.01845 1.72375 -3.42175 -2.29725 -4.55095 -8.92000 11.56400 -0.85435 -0.98450 1.37875
[298] -0.05225 -1.79065 -3.24000 6.89800 -2.88615 1.89680 -1.71995 1.23670 4.76065 1.91705 4.91885
[309] -3.09340 -9.62280 -6.96000 10.17000 1.00150 -0.27075 3.60460 3.91925 -12.29470 -0.15000 11.58200
[320] 1.95930 -9.38075 -1.46460 -5.29375 -1.29280 -2.95000 10.18800 -1.85795 -2.52690 3.46760 0.71515
[331] -3.87005 -4.41000 14.17200 5.00880 -1.75035 -7.26945 -4.97815 0.33920 -4.99000 -0.38000 13.42315
[342] 0.44745 -12.82670 5.65645 -1.60595 -4.19000 10.42800 -0.91455 2.01905 -1.22470 -6.72005 -2.37540
[353] -6.62000 11.03000 -0.16420 4.67650 2.10160 -5.40605 -5.63525 -7.84000 13.38400 -4.76505 -2.09520
[364] -0.21815 -5.53800 0.89805 0.84000 -3.79800 15.20915 -5.04190 2.85030 -3.54720 5.66655 -2.09000
[375] -3.51800 -2.05115 4.75600 1.64015 -2.93645 -2.78400 -4.60000 7.83000 7.58955 -4.06370 -3.14205
[386] -1.00330 -0.78590 -3.09000 16.99000 -1.75450 -0.17840 -6.17105 3.67985 -7.73185 -1.45000 -0.48000
[397] -0.03625 0.64765 -0.88770 4.37420 -3.41025 -4.16000 2.30600 3.64675 0.65160 -1.86050 4.44755
[408] -4.64435 0.59000 7.70800 0.13515 -3.63075 4.07175 -3.44855 1.61700 -2.69000 6.99000 -6.32835
[419] 0.06035 0.66905 2.09225 -8.90405 2.90000 -5.14800 1.27180 11.69970 18.22670 -5.02240 -11.80655
[430] -11.48000 22.61800 -2.89710 -21.47555 4.60950 0.11945 -1.44270 -1.49000 2.91800 5.56680 -4.15875
[441] -0.84530 -4.80830 2.38945 0.68000 6.40800 1.46045 6.47015 -3.83785 3.01765 -13.76620 3.80000
[452] 7.04600 -9.70915 5.06240 -4.42255 -4.30895 -0.48565 1.48000 1.01400 0.41325 4.26235 -0.52185
[463] -2.46555 0.05000 -1.16000 -0.26780 2.31460 7.02870 0.74975 -6.08455 -2.63000 2.65200 -5.02335
[474] 2.71820 14.30270 -14.36495 -2.38640 -4.52000 8.25600 -3.06855 -0.76365 4.48095 5.21815 -4.52365
[485] -1.52000 12.16000 -1.96610 8.04025 10.50445 -17.61300 -13.53880 -6.99000 7.25800 9.58530 3.87375
[496] -2.82975 2.68740 -11.12640 -3.71000 -2.09800 11.13375 -4.50495 -4.49020 3.06840 -3.24390 2.42000
[507] 10.54600 -6.76650 -1.39590 2.19665 -2.40210 -2.70515 -4.53000 6.81400 -2.62700 1.78745 -2.80275
[518] 5.00345 -5.79180 -0.41000 3.71200 1.10155 -0.99680 -1.49750 2.46750 -3.66735 -1.33000 1.89400
[529] 2.14050 -0.45820 -2.64025 1.64115 -2.63910 2.86000 -0.43000 -0.02565 -0.69105 0.18560 -0.08540
[540] -2.21505 -2.10000 7.17400 4.28040 -3.66650 -1.47560 1.35750 -2.93310 -2.36000 -0.04400 3.63380
[551] 1.57210 0.75930 -1.84085 -1.37640 -3.31000 4.11800 0.87930 3.56600 -0.25750 -2.47415 -2.73090
[562] -3.30000 5.78600 -3.72375 -0.40445 2.40250 1.75210 -3.30980 -2.22000 4.11600 -1.04385 1.09985
[573] 0.12310 -0.10000 0.85585 -3.19015 2.50105 2.59145 -9.87755 4.65000 4.64000 -0.38080 -2.83590
[584] 2.52765 -0.46655 -1.21260 -1.33000 7.19000 5.16895 -11.32840 5.50915 -0.29850 -4.34405 -1.16000
[595] 1.99200 0.94850 -0.11665 -1.32835 3.87565 -4.49720 -1.83000 10.71400 -3.08910 -2.57270 0.14165
[606] 0.67460 -3.13245 -10.58000 11.04000 4.67700 -0.76965 -8.59540 5.31355 -0.48550 -9.83000 13.65000
[617] 1.98135 -1.52210 -2.02930 -1.18050 -6.26230 4.41000 -1.84800 12.20420 -0.73490 -5.45060 2.30475
[628] -5.93990 -0.98000 8.14800 0.68375 -1.57665 -1.89040 1.30625 -6.66715 -1.09000 5.37200 6.03350
[639] -2.11330 -3.12840 7.26250 -9.10530 -7.88000 6.99800 1.24900 -1.71020 -0.42185 1.02915 -2.83645
[650] -2.63000 5.59000 0.04545 2.03685 5.21010 -2.90810 -7.58070 -0.74000 4.79800 -0.78570 6.57080
[661] -1.00055 0.71075 -8.20515 -2.34000 8.04000 5.03540 3.79530 1.00215 -4.29350 -8.57975 -3.60000
[672] 10.74600 0.03990 -1.48135 1.15855 -2.66635 -6.04255 -1.27000 6.89800 1.07795 -1.42805 -4.52400
[683] 3.48210 -10.79030 1.01000 10.82400 -2.22530 -0.37040 -3.96645 3.98060 -8.26920 4.43000 2.02000
[694] 5.57785 1.46695 -5.79030 1.21475 -4.58515 -0.81000 13.70000 1.10770 4.14880 -6.56570 -3.85860
[705] -5.86435 -2.84000 8.22800 0.06675 -0.60955 -2.53285 1.06340 2.27175 1.30000 7.91000 -11.03340
[716] -4.43140 3.40160 0.42545 -4.02465 -4.39000 14.80000 -11.49595 3.76795 9.23025 -3.32815 -7.07725
[727] -2.19000 11.81600 0.91175 -4.06940 -3.73460 -1.05750 -6.47590 -0.52000 7.66400 6.21025 -2.67520
[738] 1.26305 -1.17585 -6.75250 -4.32000 11.27200 -5.91505 1.08715 -0.00055 -3.66290 3.58325 -6.39000
[749] 13.22600 0.88190
I want to compare The distribution of this data with the one of a normal, so, I have the following code to try to do it, it first creates a histogram of the vector, then figure out the proportion between the frecuency and density, and finally I overlap a normal to the histogram using the lines function and the multiplier I just figured out:
histogram <- hist(Datadiff, breaks = 40)
multiplier2 <- unique(histogram$counts/histogram$density)[1]
lines(x = Datadiff, dnorm(Datadiff, sd = sd(Datadiff))*multiplier2, lwd = 3, lty = 2)
When the comparison is plotted, I get messy lines instead of the normal distribution:
Could please anyone point what is the problem?
If you want to keep frequency on the Y-axis instead of density, just use a sequence within the observed range in dnorm.
Your old code
histogram <- hist(Datadiff, breaks = 40)
multiplier2 <- unique(histogram$counts/histogram$density)[1]
New modification: make a sequence spanning the range of Datadiff
seq1 <- seq(min(Datadiff),max(Datadiff),.1)
Plot this sequence over the histogram
lines(x = seq1, dnorm(seq1,sd = sd(Datadiff))*multiplier2, lwd = 3, lty = 2)
You could also replace the mean of dnorm with the observed mean mean = mean(Datadiff)
You could use curve. Set freq=FALSE in histogram to get agreeing densities in both plots.
hist(Datadiff, breaks=40, freq=FALSE)
curve(dnorm(x, mean=mean(Datadiff), sd=sd(Datadiff)),
add=TRUE, col=2, lty=2)
legend("topright", c("empirical", "theoretical normal"), cex=.8, lty=1:2, col=1:2)
(If you want to compare with a standard normal don't use mean=mean(Datadiff), sd=sd(Datadiff), let your dnorm(.) default to mean=0, sd=1.)
Produces
Data
Datadiff <- c(-1.36785, -0.8615, 11.15045, -6.67, -20.52355, 8.738, -10.7468,
5.3824, -1.8901, 3.35195, 1.17, 7.3426, 2.81535, -0.9266, -9.56,
-3.72, 1.4636, 0.8247, 9.708, 7.332, -1.36575, 2.78635, 6.6637,
-1.15, -2.8612, 16.458, -0.05225, -3.0934, 1.9593, -3.87005,
0.44745, -6.62, -0.21815, -3.518, -1.0033, -0.03625, -4.64435,
0.06035, -11.48, -0.8453, 7.046, -2.46555, 2.7182, -1.52, -2.82975,
10.546, 5.00345, 2.1405, -2.21505, 1.5721, -3.3, 0.1231, 2.52765,
1.992, 0.6746, 1.98135, -5.9399, -2.1133, -2.63, -1.00055, 10.746,
3.4821, 5.57785, -5.86435, -4.4314, -2.19, 1.26305, 13.226, -0.01415,
-1.97, -2.1243, -8.4482, 6.576, 0.6822, 5.1788, -13.1987, -15.50855,
-3.46, -2.63695, 0.7464, -8.99235, -0.9024, -1.53, -1.79115,
18.142, -1.55485, -0.6195, -2.0266, -5.9687, -1.3856, -15.19,
0.89995, 6.794, -1.30305, 3.01845, -1.79065, -9.6228, -9.38075,
-4.41, -12.8267, 11.03, -5.538, -2.05115, -0.7859, 0.64765, 0.59,
0.66905, 22.618, -4.8083, -9.70915, 0.05, 14.3027, 12.16, 2.6874,
-6.7665, -5.7918, -0.4582, -2.1, 0.7593, 5.786, -0.1, -0.46655,
0.9485, -3.13245, -1.5221, -0.98, -3.1284, 5.59, 0.71075, 0.0399,
-10.7903, 1.46695, -2.84, 3.4016, 11.816, -1.17585, 0.8819, 2.6835,
6.622, 2.20255, -9.4959, -4.48095, 3.64315, -8.20225, 4.32, -0.65105,
-2.29, 0.83655, -0.1267, -3.63, -2.6286, 10.514, -14.12515, -2.22105,
-5.3065, 0.5826, -0.83785, -0.93, -5.0779, -1.368, -3.76125,
-3.98745, -2.09495, 1.72375, -3.24, -6.96, -1.4646, 14.172, 5.65645,
-0.1642, 0.89805, 4.756, -3.09, -0.8877, 7.708, 2.09225, -2.8971,
2.38945, 5.0624, -1.16, -14.36495, -1.9661, -11.1264, -1.3959,
-0.41, -2.64025, 7.174, -1.84085, -3.72375, 0.85585, -1.2126,
-0.11665, -10.58, -2.0293, 8.148, 7.2625, 0.04545, -8.20515,
-1.48135, 1.01, -5.7903, 8.228, 0.42545, 0.91175, -6.7525, -4.2698,
-0.8247, 2.0385, 0.13885, 0.05825, -0.46, -1.6177, -3.456, 6.84655,
4.6918, -12.01, 2.26105, 4.558, -3.69285, -3.33635, 14.49105,
-5.472, -3.08, -8.7, 1.145, 2.036, 5.9448, 16.65735, -10.8584,
-1.463, -2.23, -3.42175, 6.898, 10.17, -5.29375, 5.0088, -1.60595,
4.6765, 0.84, 1.64015, 16.99, 4.3742, 0.13515, -8.90405, -21.47555,
0.68, -4.42255, -0.2678, -2.3864, 8.04025, -3.71, 2.19665, 3.712,
1.64115, 4.2804, -1.3764, -0.40445, -3.19015, -1.33, -1.32835,
11.04, -1.1805, 0.68375, -9.1053, 2.03685, -2.34, 1.15855, 10.824,
1.21475, 0.06675, -4.02465, -4.0694, -4.32, -2.28975, -1.9953,
-0.19295, -1.06, 3.35215, 4.088, 23.66225, 0.2967, -9.3897, 1.2021,
11.164, 0.04115, 5.0418, 0.61605, -4.5202, -6.9, -1.7435, 9.59,
16.496, -1.46245, 5.7376, -10.584, -3.12405, -3.51, 2.38375,
11.448, -2.29725, -2.88615, 1.0015, -1.2928, -1.75035, -4.19,
2.1016, -3.798, -2.93645, -1.7545, -3.41025, -3.63075, 2.9, 4.6095,
6.408, -4.30895, 2.3146, -4.52, 10.50445, -2.098, -2.4021, 1.10155,
-2.6391, -3.6665, -3.31, 2.4025, 2.50105, 7.19, 3.87565, 4.677,
-6.2623, -1.57665, -7.88, 5.2101, 8.04, -2.66635, -2.2253, -4.58515,
-0.60955, -4.39, -3.7346, 11.272, -1.27, 1.84275, 1.83205, 3.858,
5.94525, 5.76705, -16.2386, 2.22515, 1.7, -0.95415, 9.18425,
-2.31855, -5.3029, -5.81, -1.855, 2.764, 7.3874, -0.70365, -2.05375,
-4.4283, -2.35745, -4.41, -2.5129, 13.748, 1.7395, -0.749, -4.55095,
1.8968, -0.27075, -2.95, -7.26945, 10.428, -5.40605, 15.20915,
-2.784, -0.1784, -4.16, 4.07175, -5.148, 0.11945, 1.46045, -0.48565,
7.0287, 8.256, -17.613, 11.13375, -2.70515, -0.9968, 2.86, -1.4756,
4.118, 1.7521, 2.59145, 5.16895, -4.4972, -0.76965, 4.41, -1.8904,
6.998, -2.9081, 5.0354, -6.04255, -0.3704, -0.81, -2.53285, 14.8,
-1.0575, -5.91505, 6.634, -4.70575, 2.043, -1.27255, -8.91095,
3.88775, -2.25, -1.77935, 5.432, -3.40435, -3.9124, -2.3, 0.96565,
5.328, 0.36355, 19.79725, -2.1662, -0.2948, -1.1552, -16.34,
5.8247, 11.214, 3.5192, -3.02445, -10.64685, 0.83135, -8.92,
-1.71995, 3.6046, 10.188, -4.97815, -0.91455, -5.63525, -5.0419,
-4.6, -6.17105, 2.306, -3.44855, 1.2718, -1.4427, 6.47015, 1.48,
0.74975, -3.06855, -13.5388, -4.50495, -4.53, -1.4975, -0.43,
1.3575, 0.8793, -3.3098, -9.87755, -11.3284, -1.83, -8.5954,
-1.848, 1.30625, 1.249, -7.5807, 3.7953, -1.27, -3.96645, 13.7,
1.0634, -11.49595, -6.4759, 1.08715, -3.13965, 3.6715, -3.51635,
0.3501, -1.21, -12.3292, -5.244, -0.26525, 10.1788, -7.49, 6.02935,
1.814, 2.3713, -0.39985, -11.26815, -1.36595, -12.96, 0.0857,
0.74145, 18.55, -2.38335, 0.3384, -9.6309, 0.291, -7.78, -3.44695,
11.564, 1.2367, 3.91925, -1.85795, 0.3392, 2.01905, -7.84, 2.8503,
7.83, 3.67985, 3.64675, 1.617, 11.6997, -1.49, -3.83785, 1.014,
-6.08455, -0.76365, -6.99, -4.4902, 6.814, 2.4675, -0.02565,
-2.9331, 3.566, -2.22, 4.65, 5.50915, 10.714, 5.31355, 12.2042,
-6.66715, -1.7102, -0.74, 1.00215, 6.898, 3.9806, 1.1077, 2.27175,
3.76795, -0.52, -0.00055, -1.6705, -1.009, -3.32, 3.38085, 7.998,
-0.08525, 8.21195, 0.3263, 2.98075, -0.15, -2.27235, 0.6842,
0.331, 0.52635, 1.62, -5.1443, 12.1, -3.1422, 0.49035, 1.93415,
-5.7134, 1.4213, -0.95, 0.3376, 15.324, 0.31755, -0.85435, 4.76065,
-12.2947, -2.5269, -4.99, -1.2247, 13.384, -3.5472, 7.58955,
-7.73185, 0.6516, -2.69, 18.2267, 2.918, 3.01765, 0.41325, -2.63,
4.48095, 7.258, 3.0684, -2.627, -3.66735, -0.69105, -2.36, -0.2575,
4.116, 4.64, -0.2985, -3.0891, -0.4855, -0.7349, -1.09, -0.42185,
4.798, -4.2935, 1.07795, -8.2692, 4.1488, 1.3, 9.23025, 7.664,
-3.6629, -0.2892, -1.00205, 9.078, -5.7087, -2.2173, -4.10745,
19.021, 0.37, -10.85725, 7.49445, -4.3211, -0.9439, -2.53, 0.39335,
10.89, 1.67195, 1.0579, -4.9017, -9.7918, -3.2305, -7.6, -3.75035,
21.88, 0.13705, 2.3085, -4.005, -0.9845, 1.91705, -0.15, 3.4676,
-0.38, -6.72005, -4.76505, 5.66655, -4.0637, -1.45, -1.8605,
6.99, -5.0224, 5.5668, -13.7662, 4.26235, 2.652, 5.21815, 9.5853,
-3.2439, 1.78745, -1.33, 0.1856, -0.044, -2.47415, -1.04385,
-0.3808, -4.34405, -2.5727, -9.83, -5.4506, 5.372, 1.02915, -0.7857,
-8.57975, -1.42805, 4.43, -6.5657, 7.91, -3.32815, 6.21025, 3.58325,
-0.42435, -0.7735, -0.6028, 5.08605, 13.6661, -6.7, -1.5533,
10.262, -6.22135, -0.14045, -3.16, 0.67445, 6.504, 0.56145, -0.5133,
-9.1829, 4.3799, -4.0569, -1.06, -3.63245, 15.42, 7.43265, -6.28715,
-7.9766, -2.49665, -8.25, 1.37875, 4.91885, 11.582, 0.71515,
13.42315, -2.3754, -2.0952, -2.09, -3.14205, -0.48, 4.44755,
-6.32835, -11.80655, -4.15875, 3.8, -0.52185, -5.02335, -4.52365,
3.87375, 2.42, -2.80275, 1.894, -0.0854, 3.6338, -2.7309, 1.09985,
-2.8359, -1.16, 0.14165, 13.65, 2.30475, 6.0335, -2.83645, 6.5708,
-3.6, -4.524, 2.02, -3.8586, -11.0334, -7.07725, -2.6752, -6.39
)

Rolling window in R

I have part of this code which is the initial step of a rolling iteration
for (u in 1:5605){
for (j in 1:498){
work.on.col = j
work.dt = data[u:(u+365),work.on.col] # u:(u+365-1) considers the rolling window
}
}
So basically, this makes a rolling window from u == 1 to u == 5605 for each j. However, this is a step by step (or in this case: a day by day) rolling algorithm. What I want to change it to, is to do so
By 30 days: instead or rolling day by day, it should roll every 30 days (by this I meant here that the rolling window will REMOVE 30 days, then add 30 days to the window, thus rolling the 365 day-long window). OR
By identifying the month. For example, first iteration will start with daily data from January 2000 to January 2001. And the next iteration will start with February 2000 to February 2001, and so on (this approach is more preferable).
Data
> dput(data)
structure(list(Dates = structure(c(820454400, 820540800, 820627200,
820713600, 820800000, 821059200, 821145600, 821232000, 821318400,
821404800, 821664000, 821750400, 821836800, 821923200, 822009600,
822268800, 822355200, 822441600, 822528000, 822614400, 822873600,
822960000, 823046400, 823132800, 823219200, 823478400, 823564800,
823651200, 823737600, 823824000, 824083200, 824169600, 824256000,
824342400, 824428800, 824688000, 824774400, 824860800, 824947200,
825033600, 825292800, 825379200, 825465600, 825552000, 825638400,
825897600, 825984000, 826070400, 826156800, 826243200, 826502400,
826588800, 826675200, 826761600, 826848000, 827107200, 827193600,
827280000, 827366400, 827452800, 827712000, 827798400, 827884800,
827971200, 828057600, 828316800, 828403200, 828489600, 828576000,
828662400, 828921600, 829008000, 829094400, 829180800, 829267200,
829526400, 829612800, 829699200, 829785600, 829872000, 830131200,
830217600, 830304000, 830390400, 830476800, 830736000, 830822400,
830908800, 830995200, 831081600, 831340800, 831427200, 831513600,
831600000, 831686400, 831945600, 832032000, 832118400, 832204800,
832291200, 832550400, 832636800, 832723200, 832809600, 832896000,
833155200, 833241600, 833328000, 833414400, 833500800, 833760000,
833846400, 833932800, 834019200, 834105600, 834364800, 834451200,
834537600, 834624000, 834710400, 834969600, 835056000, 835142400,
835228800, 835315200, 835574400, 835660800, 835747200, 835833600,
835920000, 836179200, 836265600, 836352000, 836438400, 836524800,
836784000, 836870400, 836956800, 837043200, 837129600, 837388800,
837475200, 837561600, 837648000, 837734400, 837993600, 838080000,
838166400, 838252800, 838339200, 838598400, 838684800, 838771200,
838857600, 838944000, 839203200, 839289600, 839376000, 839462400,
839548800, 839808000, 839894400, 839980800, 840067200, 840153600,
840412800, 840499200, 840585600, 840672000, 840758400, 841017600,
841104000, 841190400, 841276800, 841363200, 841622400, 841708800,
841795200, 841881600, 841968000, 842227200, 842313600, 842400000,
842486400, 842572800, 842832000, 842918400, 843004800, 843091200,
843177600, 843436800, 843523200, 843609600, 843696000, 843782400,
844041600, 844128000, 844214400, 844300800, 844387200, 844646400,
844732800, 844819200, 844905600, 844992000, 845251200, 845337600,
845424000, 845510400, 845596800, 845856000, 845942400, 846028800,
846115200, 846201600, 846460800, 846547200, 846633600, 846720000,
846806400, 847065600, 847152000, 847238400, 847324800, 847411200,
847670400, 847756800, 847843200, 847929600, 848016000, 848275200,
848361600, 848448000, 848534400, 848620800, 848880000, 848966400,
849052800, 849139200, 849225600, 849484800, 849571200, 849657600,
849744000, 849830400, 850089600, 850176000, 850262400, 850348800,
850435200, 850694400, 850780800, 850867200, 850953600, 851040000,
851299200, 851385600, 851472000, 851558400, 851644800, 851904000,
851990400, 852076800, 852163200, 852249600, 852508800, 852595200,
852681600, 852768000, 852854400, 853113600, 853200000, 853286400,
853372800, 853459200, 853718400, 853804800, 853891200, 853977600,
854064000, 854323200, 854409600, 854496000, 854582400, 854668800,
854928000, 855014400, 855100800, 855187200, 855273600, 855532800,
855619200, 855705600, 855792000, 855878400, 856137600, 856224000,
856310400, 856396800, 856483200, 856742400, 856828800, 856915200,
857001600, 857088000, 857347200, 857433600, 857520000, 857606400,
857692800, 857952000, 858038400, 858124800, 858211200, 858297600,
858556800, 858643200, 858729600, 858816000, 858902400, 859161600,
859248000, 859334400, 859420800, 859507200, 859766400, 859852800,
859939200, 860025600, 860112000, 860371200, 860457600, 860544000,
860630400, 860716800, 860976000, 861062400, 861148800, 861235200,
861321600, 861580800, 861667200, 861753600, 861840000, 861926400,
862185600, 862272000, 862358400, 862444800, 862531200, 862790400,
862876800, 862963200, 863049600, 863136000, 863395200, 863481600,
863568000, 863654400, 863740800, 8.64e+08, 864086400, 864172800,
864259200, 864345600, 864604800, 864691200, 864777600, 864864000,
864950400, 865209600, 865296000, 865382400, 865468800, 865555200,
865814400, 865900800, 865987200, 866073600, 866160000, 866419200,
866505600, 866592000, 866678400, 866764800, 867024000, 867110400,
867196800, 867283200, 867369600, 867628800, 867715200, 867801600,
867888000, 867974400, 868233600, 868320000, 868406400, 868492800,
868579200, 868838400, 868924800, 869011200, 869097600, 869184000,
869443200, 869529600, 869616000, 869702400, 869788800, 870048000,
870134400, 870220800, 870307200, 870393600, 870652800, 870739200,
870825600, 870912000, 870998400, 871257600, 871344000, 871430400,
871516800, 871603200, 871862400, 871948800, 872035200, 872121600,
872208000, 872467200, 872553600, 872640000, 872726400, 872812800,
873072000, 873158400, 873244800, 873331200, 873417600, 873676800,
873763200, 873849600, 873936000, 874022400, 874281600, 874368000,
874454400, 874540800, 874627200, 874886400, 874972800, 875059200,
875145600, 875232000, 875491200, 875577600, 875664000, 875750400,
875836800, 876096000, 876182400, 876268800, 876355200, 876441600,
876700800, 876787200, 876873600, 876960000, 877046400, 877305600,
877392000, 877478400, 877564800, 877651200, 877910400, 877996800,
878083200, 878169600, 878256000, 878515200, 878601600, 878688000,
878774400, 878860800, 879120000, 879206400, 879292800, 879379200,
879465600, 879724800, 879811200, 879897600, 879984000, 880070400,
880329600, 880416000, 880502400, 880588800, 880675200, 880934400,
881020800, 881107200, 881193600, 881280000, 881539200, 881625600,
881712000, 881798400, 881884800, 882144000, 882230400, 882316800,
882403200, 882489600, 882748800, 882835200, 882921600, 883008000,
883094400, 883353600, 883440000, 883526400, 883612800, 883699200,
883958400, 884044800, 884131200, 884217600, 884304000, 884563200,
884649600, 884736000, 884822400, 884908800, 885168000, 885254400,
885340800, 885427200, 885513600, 885772800, 885859200, 885945600,
886032000, 886118400, 886377600, 886464000, 886550400, 886636800,
886723200, 886982400, 887068800, 887155200, 887241600, 887328000,
887587200, 887673600, 887760000, 887846400, 887932800, 888192000,
888278400, 888364800, 888451200, 888537600, 888796800, 888883200,
888969600, 889056000, 889142400, 889401600, 889488000, 889574400,
889660800, 889747200, 890006400, 890092800, 890179200, 890265600,
890352000, 890611200, 890697600, 890784000, 890870400, 890956800,
891216000, 891302400, 891388800, 891475200, 891561600, 891820800,
891907200, 891993600, 892080000, 892166400, 892425600, 892512000,
892598400, 892684800, 892771200, 893030400, 893116800, 893203200,
893289600, 893376000, 893635200, 893721600, 893808000, 893894400,
893980800, 894240000, 894326400, 894412800, 894499200, 894585600,
894844800, 894931200, 895017600, 895104000, 895190400, 895449600,
895536000, 895622400, 895708800, 895795200, 896054400, 896140800,
896227200, 896313600, 896400000, 896659200, 896745600, 896832000,
896918400, 897004800, 897264000, 897350400, 897436800, 897523200,
897609600, 897868800, 897955200, 898041600, 898128000, 898214400,
898473600, 898560000, 898646400, 898732800, 898819200, 899078400,
899164800, 899251200, 899337600, 899424000, 899683200, 899769600,
899856000, 899942400, 900028800, 900288000, 900374400, 900460800,
900547200, 900633600, 900892800, 900979200, 901065600, 901152000,
901238400, 901497600, 901584000, 901670400, 901756800, 901843200,
902102400, 902188800, 902275200, 902361600, 902448000, 902707200,
902793600, 902880000, 902966400, 903052800, 903312000, 903398400,
903484800, 903571200, 903657600, 903916800, 904003200, 904089600,
904176000, 904262400, 904521600, 904608000, 904694400, 904780800,
904867200), class = c("POSIXct", "POSIXt"), tzone = "UTC"), `1` = c(9.3424,
9.3424, 9.3983, 9.5102, 9.3144, 9.4822, 9.3983, 9.0537, 9.1381,
9.1099, 9.0537, 8.9975, 8.7444, 8.8007, 8.8007, 8.7163, 8.8569,
8.9412, 8.9131, 9.0537, 9.0537, 9.4474, 9.5036, 9.6723, 9.6723,
9.7566, 9.5879, 9.7566, 9.841, 9.8129, 9.9535, 9.841, 9.6442,
9.8972, 9.7285, 9.7285, 9.6161, 9.2787, 9.3911, 9.363, 9.2224,
9.1099, 9.2787, 9.3911, 9.4474, 9.841, 9.7285, 9.7004, 9.8691,
9.5598, 9.5036, 9.5317, 9.363, 9.4755, 9.2224, 9.1099, 9.2505,
9.1381, 9.2787, 9.2224, 9.1381, 9.2224, 9.1099, 9.1381, 9.1662,
9.4192, 9.3911, 9.3911, 9.4474, 9.4474, 9.7004, 9.5317, 9.2787,
9.3326, 9.3892, 9.3326, 9.2761, 9.2195, 9.2761, 9.4458, 9.3609,
9.4458, 9.163, 9.2761, 9.1912, 9.3044, 9.1912, 9.1912, 9.0215,
8.9084, 8.965, 8.9367, 8.9367, 8.9933, 9.0781, 9.2478, 9.163,
9.2761, 9.2478, 9.3609, 9.3892, 9.3609, 9.5023, 9.3892, 9.672,
9.672, 9.5872, 9.5306, 9.7003, 9.7568, 9.6437, 9.672, 9.9265,
9.8417, 9.87, 9.8134, 9.7568, 9.672, 9.7568, 9.7003, 9.7286,
9.7851, 9.7851, 9.672, 9.7851, 9.7851, 9.8417, 9.8134, 9.8983,
9.8417, 9.8417, 9.8134, 9.87, 9.87, 9.672, 9.5306, 9.4175, 9.5872,
9.896, 10.0666, 9.896, 9.8676, 9.7538, 10.2657, 10.095, 10.095,
9.9244, 9.9529, 10.0382, 10.1519, 10.0382, 10.0666, 10.0097,
10.1235, 10.2941, 10.351, 10.4363, 10.2941, 10.4079, 10.5785,
10.55, 10.4647, 10.4363, 10.5216, 10.7775, 10.806, 10.806, 10.6922,
10.8344, 10.6922, 10.5785, 10.55, 10.4363, 10.2941, 10.2657,
10.2657, 10.351, 10.4363, 10.5216, 10.5785, 10.6922, 10.6922,
10.6353, 10.7207, 10.8628, 10.9197, 10.8913, 10.806, 11.005,
10.8344, 10.8628, 10.9197, 11.005, 11.0619, 11.2041, 11.2041,
11.2325, 11.2325, 11.2894, 11.46, 11.46, 11.5453, 11.2325, 11.1734,
11.5163, 11.8306, 11.7163, 11.6877, 11.9164, 12.0878, 11.8878,
11.6306, 11.602, 11.6592, 11.4306, 11.3448, 11.5734, 11.4306,
11.5734, 11.4306, 11.4877, 11.6877, 12.0592, 12.0878, 12.2021,
12.1735, 12.0021, 12.0021, 12.2307, 12.2307, 12.1735, 12.2878,
12.3164, 12.5165, 12.7451, 13.0308, 12.8594, 12.7451, 12.7451,
12.7451, 12.6308, 12.4307, 12.1735, 12.0878, 12.0592, 12.3164,
12.1735, 11.9449, 11.6877, 11.7449, 11.5449, 11.602, 11.5734,
11.9735, 12.0592, 12.0021, 12.0592, 12.0592, 12.0878, 12.0878,
11.9449, 11.602, 11.602, 11.5163, 11.7449, 11.6306, 11.8878,
11.7163, 11.8306, 12.0592, 12.0284, 12.258, 12.2293, 12.7173,
12.6599, 12.6599, 12.6599, 12.947, 12.4877, 12.5164, 12.3154,
12.2867, 12.2006, 12.459, 12.4877, 12.459, 12.5738, 12.4303,
12.5451, 12.8035, 12.8322, 12.8609, 13.0905, 13.435, 13.3776,
13.3776, 13.6934, 13.5212, 13.3202, 13.2054, 13.3489, 13.435,
13.2915, 13.2054, 12.9183, 13.0905, 12.8322, 13.4924, 13.2054,
13.5499, 13.8082, 13.5786, 13.5786, 13.435, 13.2915, 13.7508,
13.6647, 13.4924, 13.3489, 13.2628, 13.6647, 13.5499, 13.6073,
13.3202, 13.3202, 12.8896, 12.7748, 12.8322, 12.8322, 13.1193,
12.9183, 12.9757, 12.7173, 13.0044, 12.4062, 12.7524, 13.0409,
13.4448, 13.5025, 13.3871, 13.5602, 13.9353, 13.8199, 13.6756,
13.5891, 13.6468, 13.993, 14.0796, 14.0796, 14.3392, 14.6277,
14.5989, 14.4546, 14.4258, 14.4835, 14.7143, 14.8297, 14.9739,
15.4933, 15.2913, 15.2625, 15.0028, 14.6277, 14.6277, 14.772,
14.772, 14.772, 14.57, 14.5412, 14.5412, 14.4546, 14.5989, 14.5123,
14.4546, 14.772, 15.0028, 14.9162, 15.1471, 15.3202, 15.3779,
15.2336, 15.0894, 14.9451, 15.3779, 15.4067, 14.9739, 15.7097,
15.4789, 15.2048, 15.6375, 15.4067, 15.2192, 15.349, 15.7962,
15.7962, 15.4789, 15.6231, 15.3346, 15.1759, 14.8776, 14.8921,
15.0369, 14.9935, 14.5879, 14.385, 14.3416, 14.6313, 14.8631,
14.7327, 14.7762, 14.6313, 14.8631, 15.0369, 15.1673, 14.8052,
14.6603, 14.7037, 14.6458, 14.8341, 14.8196, 14.8486, 14.8196,
14.5589, 14.7472, 14.0808, 14.472, 14.2981, 14.3706, 14.1533,
14.0663, 13.8201, 13.8635, 13.9649, 13.878, 13.8925, 13.8925,
14.414, 14.5299, 14.5009, 14.3416, 14.0953, 14.0808, 13.849,
13.7911, 14.3706, 14.3271, 14.7037, 14.6023, 14.7762, 14.9355,
15.0224, 14.921, 14.6313, 14.5589, 14.7327, 14.9355, 14.8196,
14.8486, 14.95, 14.9066, 15.0659, 15.2832, 15.1818, 15.0514,
14.9257, 14.9257, 15.0857, 14.7948, 14.8238, 14.8675, 14.7657,
14.8238, 14.7802, 14.3729, 14.3147, 13.5582, 14.2565, 14.1401,
14.0092, 14.271, 14.4893, 14.6638, 14.8384, 14.562, 14.5329,
14.5911, 14.562, 14.6056, 14.7948, 14.9984, 15.0857, 14.9548,
15.1439, 15.2312, 15.3476, 15.1439, 15.3476, 15.333, 15.333,
15.1293, 15.6531, 15.6821, 15.8713, 15.7258, 15.8276, 15.6821,
15.9585, 15.7694, 15.5512, 15.5076, 15.784, 15.9731, 15.6821,
15.1875, 15.0421, 15.3767, 15.1002, 15.013, 15.013, 15.1875,
15.333, 15.5803, 15.2603, 15.2603, 15.6967, 15.784, 15.5221,
15.624, 15.8422, 15.6531, 16.1913, 16.3123, 16.3415, 16.2247,
16.3708, 16.3708, 16.6774, 16.5168, 16.4438, 16.3269, 16.1663,
16.5168, 16.5752, 16.7943, 16.546, 16.6336, 16.473, 16.4438,
16.5022, 16.7651, 16.7505, 17.1886, 17.1009, 17.2616, 17.3054,
17.3054, 17.5537, 17.4952, 17.2616, 17.3492, 17.5098, 17.4806,
17.466, 17.4076, 17.4806, 17.5683, 17.5391, 17.3346, 17.466,
17.7289, 17.6559, 17.9626, 18.1086, 18.24, 18.1962, 18.2108,
18.2254, 18.0502, 18.0064, 18.1962, 18.0356, 17.9334, 17.4222,
17.6121, 17.6267, 17.32, 17.5975, 17.7581, 18.0794, 18.2692,
18.0356, 17.9918, 17.7289, 17.8457, 17.8457, 17.5653, 17.6387,
17.3601, 16.8909, 17.536, 17.1401, 17.0522, 16.9495, 16.9202,
16.8469, 16.7443, 16.4657, 16.5683, 17.1548, 17.0961, 16.9935,
16.8469, 16.5536, 16.7296, 17.0082, 16.9789, 17.1988, 17.2134,
17.0375, 17.492, 17.712, 17.6093, 17.9319, 17.6826, 17.6826,
17.6826, 17.536, 17.4774, 17.5653, 17.4041, 17.1841, 17.1841,
17.0082, 17.1255, 17.6533, 17.448, 17.448, 17.5947, 17.536, 18.0052,
18.0932, 18.2985, 18.7383, 19.1782, 18.8263, 18.8849, 19.1195,
19.5301, 19.5301, 19.8233, 19.8526, 19.1782, 19.4421, 19.706,
19.706, 20.0579, 19.9406, 20.0872, 20.1459, 20.5858, 20.9201,
21.1849, 20.7141, 20.9789, 21.126, 21.0083, 20.4199, 20.9789,
20.4787, 20.5964, 20.5964, 20.0374, 20.155, 20.2727, 19.5666,
19.9491, 19.1252, 19.1841, 19.0664, 19.037, 19.037, 19.2723,
19.4783, 19.5372, 19.2429, 19.8902, 20.1256, 20.2139, 20.2433,
20.4199, 20.361, 20.3316, 20.6847, 19.9491, 19.5077, 18.1248,
18.5956, 18.3308, 18.9193, 18.6545), `3` = c(7.8478, 8.1167,
7.6421, 7.4048, 5.3479, 5.3004, 4.8099, 4.8732, 4.9681, 5.0473,
4.6438, 4.6042, 4.5315, 4.5156, 4.7057, 4.9117, 5.0068, 5.1494,
4.9593, 5.0068, 4.88, 4.7533, 4.3096, 4.3413, 4.5631, 4.6107,
4.6265, 4.5156, 4.9117, 4.9117, 4.8008, 4.7216, 4.6978, 4.5394,
4.4681, 4.4681, 4.6899, 4.7691, 4.6741, 4.6582, 4.4839, 4.3413,
4.2779, 4.2463, 4.1353, 4.1037, 4.1512, 4.0244, 4.1195, 4.072,
4.1829, 4.0878, 4.4205, 4.3096, 4.3572, 4.3255, 4.4047, 4.3255,
4.3413, 3.9769, 3.969, 4.1037, 4.0561, 4.0403, 4.0878, 4.167,
4.2051, 4.2527, 4.1257, 4.1257, 4.2685, 4.3003, 4.1733, 4.1575,
4.4272, 4.4272, 4.4907, 4.3955, 4.5383, 4.4431, 4.8001, 4.8398,
5.0778, 5.4586, 5.3634, 5.3, 5.4586, 5.411, 5.2524, 5.2841, 5.1413,
5.173, 5.0937, 4.9985, 5.1095, 5.2682, 5.3952, 5.411, 5.6967,
5.4586, 5.4745, 5.3317, 5.3158, 5.3158, 5.1095, 5.1095, 4.8081,
4.7287, 4.7763, 4.7128, 4.5859, 4.5542, 4.6652, 4.451, 4.4907,
4.6335, 4.6335, 4.57, 4.7287, 4.4431, 4.3479, 4.3637, 4.57, 4.5859,
4.57, 4.4114, 4.3003, 4.4193, 4.4828, 4.5542, 4.5859, 4.578,
4.4812, 4.4812, 4.4653, 4.4335, 4.4335, 4.3064, 4.1316, 4.1316,
3.8217, 3.8297, 4.0045, 4.4812, 4.1634, 4.1475, 4.068, 3.8614,
4.0998, 4.0362, 3.8773, 3.8614, 3.8614, 3.925, 3.925, 3.9091,
4.211, 4.2269, 4.1634, 4.1634, 4.1475, 4.068, 4.1316, 4.1951,
4.1316, 4.0998, 4.3382, 4.7354, 4.5447, 4.5447, 4.4653, 4.5606,
4.7672, 4.5765, 4.4335, 4.4335, 4.4812, 4.3699, 4.2428, 4.2905,
4.3143, 4.1951, 4.2269, 4.1792, 4.0998, 4.1792, 4.2905, 4.2428,
4.5845, 4.8308, 4.7831, 4.6877, 4.4494, 4.9102, 4.8149, 4.7418,
4.7736, 4.694, 4.5508, 4.4235, 4.3042, 4.519, 4.6145, 4.5667,
4.694, 4.7895, 4.71, 4.71, 4.694, 4.6463, 4.5508, 4.3917, 4.4235,
4.4235, 4.3122, 4.2962, 4.1689, 4.3281, 4.4076, 4.3599, 4.2962,
4.2326, 4.3917, 4.4554, 4.4713, 4.694, 4.9645, 5.0998, 5.2191,
5.4101, 5.2828, 5.2828, 5.1396, 5.0759, 5.0282, 5.0282, 5.0282,
5.0282, 5.0282, 5.0282, 5.5215, 5.3623, 5.3942, 5.3464, 5.1555,
5.235, 5.1396, 5.0918, 4.9964, 4.9964, 4.9645, 5.0918, 5.2032,
5.3146, 5.1873, 5.0123, 4.9645, 4.9645, 4.8532, 4.7259, 4.7736,
4.7577, 4.7577, 4.9168, 4.9805, 5.1555, 5.3623, 5.3783, 5.2669,
4.9964, 5.0123, 4.9709, 4.7479, 4.7718, 4.7638, 4.8275, 4.7319,
4.8435, 4.6523, 4.5885, 4.5407, 4.6523, 4.6045, 4.7638, 4.8275,
4.7957, 4.6523, 4.4292, 4.5089, 4.6523, 4.8116, 4.6602, 4.9311,
5.0187, 4.7797, 4.7797, 5.0665, 5.0506, 5.0187, 4.7001, 4.6523,
4.8275, 4.7319, 4.5248, 4.6523, 4.6841, 4.6682, 4.6523, 4.5089,
4.2938, 4.5089, 4.3416, 4.238, 4.238, 4.238, 4.4292, 4.4451,
4.9231, 5.1621, 5.2577, 5.2258, 5.2896, 5.4489, 5.2481, 5.2481,
5.1205, 5.0886, 5.2003, 5.3598, 5.4874, 5.5353, 5.5672, 5.4874,
5.3518, 5.2641, 5.3917, 5.3598, 5.296, 5.296, 5.1365, 5.0886,
5.0727, 5.1365, 5.1843, 4.8334, 4.9291, 4.9131, 4.9929, 5.3279,
5.615, 5.9341, 5.7905, 5.9181, 5.615, 5.5193, 5.5911, 5.5831,
5.4874, 5.6549, 5.7107, 5.631, 5.5911, 5.8703, 5.9022, 5.9181,
5.9181, 6.2371, 6.0936, 5.8064, 5.6948, 5.7666, 5.1684, 5.28,
5.4156, 5.5034, 5.296, 5.296, 5.3279, 5.296, 5.2641, 5.28, 5.304,
5.1365, 4.5941, 4.5782, 4.5542, 4.5303, 4.5144, 4.4984, 4.5064,
4.4745, 4.4346, 4.6324, 4.7442, 4.7442, 4.8081, 4.9199, 4.7762,
4.6164, 4.6324, 4.8161, 4.7921, 4.7762, 4.7362, 4.7362, 4.7362,
4.8081, 4.7362, 4.7442, 4.9119, 4.8241, 4.7762, 4.6971, 4.7287,
4.7762, 4.8078, 4.9659, 5.0925, 5.045, 4.9106, 5.0925, 5.0213,
5.1715, 5.3613, 5.1241, 5.2506, 5.2111, 5.4957, 5.2506, 5.4562,
5.4088, 5.1636, 4.8157, 5.0529, 4.9818, 4.9818, 5.1399, 5.1953,
5.1794, 5.2822, 5.2269, 5.219, 5.1874, 5.6381, 5.7251, 5.733,
5.7092, 5.646, 5.7883, 6.2944, 6.5949, 6.5474, 6.4447, 6.4288,
6.3102, 6.3482, 6.3798, 6.3086, 6.3561, 6.269, 6.4115, 6.4669,
6.4907, 6.5223, 6.3719, 6.5698, 6.5856, 6.5065, 6.3007, 6.0632,
6.3719, 6.3323, 6.2215, 6.2057, 6.2532, 5.8574, 6.1463, 6.182,
6.0793, 6.032, 6.1741, 6.1188, 6.0714, 6.0478, 6.032, 5.9451,
5.953, 5.7162, 5.7793, 6.1267, 6.1583, 5.3214, 5.4319, 5.3846,
5.424, 5.203, 5.3451, 5.274, 5.274, 5.3056, 5.4082, 5.2582, 5.3214,
5.2582, 5.1793, 5.3688, 5.2582, 5.1319, 4.9345, 4.4529, 4.5792,
4.3819, 4.4213, 4.374, 4.6582, 4.6977, 4.5871, 4.6819, 4.6819,
4.7687, 4.8477, 5.083, 5.2173, 5.2173, 5.1225, 5.1936, 5.3675,
5.2885, 5.3359, 5.2173, 5.1541, 5.0909, 4.917, 4.9644, 4.9644,
4.9644, 5.0118, 4.9407, 4.8695, 4.8379, 4.7272, 4.7272, 4.7984,
4.7589, 4.8695, 4.8537, 4.8458, 4.9644, 4.9881, 5.0592, 5.1383,
5.0988, 5.1067, 5.2173, 5.494, 5.494, 5.4782, 5.5415, 5.5494,
5.5336, 5.5454, 5.2806, 5.4071, 5.5098, 5.5889, 5.4545, 5.5177,
5.5494, 5.5256, 5.6284, 5.5177, 5.66, 5.664, 5.6126, 5.5494,
5.6205, 5.5177, 5.3913, 5.5573, 5.4703, 5.4545, 5.5731, 5.6205,
6.0711, 5.7549, 5.7391, 5.7154, 5.7928, 5.9036, 5.9511, 5.8482,
5.6662, 5.69, 5.7374, 5.7374, 5.9353, 5.9115, 6.1094, 6.1252,
6.1648, 6.331, 6.2123, 6.418, 6.2914, 6.4259, 6.3468, 6.1806,
6.4101, 6.3389, 6.3785, 6.3151, 6.2518, 6.236, 6.3072, 6.4101,
5.9828, 5.8245, 5.7374, 5.7295, 5.7454, 5.69, 5.7612, 5.6583,
5.5792, 5.4921, 5.4921, 5.2389, 5.2784, 5.3022, 5.0569, 4.9777,
5.1914, 5.0648, 5.1518, 5.1756, 5.1281, 5.5079, 5.318, 5.1677,
5.0648, 5.0173, 5.2864, 5.2547, 5.1835, 4.9936, 5.0806, 5.1281,
5.3259, 5.6187, 5.3734, 5.413, 5.3734, 5.269, 5.2452, 5.2452,
5.2056, 5.1659, 5.2769, 5.1739, 5.0946, 5.055, 4.9441, 4.9837,
5.0471, 5.0629, 5.1343, 5.0233, 5.0075, 4.9283, 4.8015, 4.8015,
4.7856, 4.5717, 4.3419, 4.0963, 4.0963, 4.0963, 4.0963, 4.0963,
4.0963, 4.0963, 4.0963, 4.0963, 4.0963, 4.0963, 4.0963, 4.0963,
4.0963, 4.0963, 4.0963, 4.0963, 4.0963, 4.0963, 3.407, 3.4466,
3.3278, 3.5021, 3.1693, 3.1455, 3.098), `5` = c(13.4319, 13.6184,
13.805, 13.8983, 13.8983, 13.805, 13.5252, 13.2453, 12.8722,
12.7789, 12.6857, 13.4319, 13.2453, 13.5252, 13.7117, 13.8983,
13.805, 13.8983, 13.805, 13.8983, 13.9915, 14.1781, 14.2154,
14.3089, 14.2154, 14.2154, 14.4024, 14.3089, 14.5895, 14.496,
14.3089, 14.3089, 14.3089, 14.4024, 14.496, 14.496, 14.2154,
14.2154, 14.4024, 14.4024, 14.496, 14.3089, 14.683, 14.4024,
14.496, 14.5895, 14.4024, 14.4024, 14.4024, 13.9348, 13.7478,
14.0284, 14.0284, 14.0284, 13.8413, 13.7478, 13.5607, 13.9348,
13.9348, 13.9348, 14.1219, 13.8413, 13.9348, 13.8413, 13.7478,
13.5607, 13.9348, 14.1219, 14.4024, 14.4024, 13.9348, 13.6543,
13.4672, 13.5607, 13.8413, 14.0284, 13.9348, 14.1219, 14.3089,
14.496, 14.2154, 14.3089, 14.3089, 14.3089, 14.1219, 14.3089,
14.1219, 14.3463, 14.1588, 14.065, 14.2526, 13.8775, 13.7837,
14.065, 14.1588, 14.1588, 14.065, 14.3463, 14.4401, 14.5339,
14.4401, 14.6276, 14.6276, 14.6276, 15.1902, 15.1902, 14.8152,
14.7214, 14.7214, 14.6276, 14.5339, 14.5339, 14.7214, 14.4401,
14.8152, 14.8152, 14.8152, 14.6276, 14.4401, 14.4401, 14.3463,
14.5339, 14.3463, 14.6276, 14.8152, 14.8152, 14.7214, 14.4401,
14.3463, 14.3463, 14.3463, 14.2526, 14.1588, 14.1588, 13.9713,
13.7837, 13.8775, 14.065, 13.9713, 13.3149, 13.0336, 12.9398,
12.5648, 12.8461, 12.6585, 12.5648, 12.6585, 12.6585, 12.6585,
12.8461, 12.7523, 13.1274, 13.3149, 13.3149, 13.5024, 13.5962,
13.5962, 13.915, 13.727, 13.6329, 13.5389, 13.5389, 13.6329,
13.821, 14.0184, 14.3146, 14.3146, 14.3146, 14.512, 14.3146,
14.4133, 14.512, 14.0184, 14.3146, 14.0184, 14.0184, 14.0184,
13.9197, 14.0184, 14.0184, 14.2159, 14.2159, 14.1172, 14.4133,
14.3146, 14.4133, 14.3146, 14.512, 14.8082, 14.7095, 14.6108,
14.7095, 14.9069, 15.0056, 15.0056, 15.2031, 15.1044, 15.4992,
15.4992, 15.7954, 15.9929, 15.598, 15.598, 16.0916, 16.289, 17.1775,
17.0788, 16.6839, 16.5852, 16.9801, 17.4737, 17.375, 17.1775,
16.5852, 16.6839, 16.3877, 16.8813, 16.9801, 17.1775, 17.2762,
17.2762, 17.8686, 17.4144, 17.3155, 17.2166, 17.2166, 17.3155,
17.3155, 17.3155, 17.7113, 17.6123, 17.9092, 17.6123, 17.5134,
17.4144, 17.5134, 17.1176, 17.4144, 17.4144, 17.4144, 16.9197,
17.0187, 16.8208, 16.6229, 16.6229, 16.8208, 17.2166, 17.3155,
17.2166, 16.9197, 16.6229, 17.4144, 17.4144, 17.7113, 17.7113,
18.1071, 18.1071, 18.1071, 18.206, 18.0081, 17.9092, 17.4144,
17.4144, 17.4144, 17.4144, 17.2166, 17.6123, 17.5134, 17.4144,
17.6123, 17.6123, 18.206, 17.8102, 17.3155, 16.9197, 16.8208,
16.6229, 16.5239, 15.8313, 15.7324, 15.2376, 15.8313, 15.7324,
15.8313, 15.6334, 15.6334, 15.4355, 15.2772, 15.2772, 15.178,
15.178, 15.178, 15.178, 15.0788, 15.0788, 15.0788, 15.0788, 14.8804,
14.7812, 15.0788, 15.3764, 15.2772, 15.0788, 14.8804, 14.682,
14.682, 14.5828, 14.4836, 14.3844, 14.8804, 14.9796, 14.8804,
14.7812, 14.3844, 14.3844, 14.5828, 14.3844, 14.0868, 13.8884,
13.9876, 14.2852, 14.2852, 14.4836, 14.3844, 14.3844, 14.186,
14.0868, 13.7892, 13.9876, 13.69, 13.8884, 13.9876, 14.0868,
14.2852, 13.8884, 13.69, 13.7892, 13.9876, 13.9876, 14.2852,
14.2852, 14.4836, 14.4836, 14.5828, 14.5828, 14.186, 14.2852,
14.5828, 14.3844, 14.2852, 14.5828, 14.7812, 15.0193, 14.8204,
14.522, 14.522, 15.0193, 15.4172, 15.5166, 15.7155, 15.6161,
15.6161, 15.815, 15.7155, 16.0139, 16.0139, 15.9145, 15.815,
15.9145, 15.9145, 15.7155, 15.815, 15.6161, 16.4118, 16.5113,
16.6107, 17.4065, 16.6107, 16.4118, 16.2129, 16.0139, 16.5113,
17.4065, 17.2075, 17.5059, 17.6054, 17.7049, 18.1027, 17.7049,
18.8487, 18.6995, 18.4508, 18.6498, 18.9979, 18.9979, 18.5006,
18.6, 18.5006, 18.6498, 18.7492, 18.6, 18.3017, 18.6498, 18.053,
17.6054, 17.8043, 18.3017, 18.5006, 18.4011, 18.2519, 17.8043,
17.9038, 17.9038, 17.9038, 17.8541, 17.9535, 17.9038, 17.9436,
18.0433, 18.1429, 18.1928, 17.8937, 17.4451, 17.8464, 17.4277,
17.2184, 17.48, 17.7417, 17.5847, 18.3174, 18.4221, 18.2651,
18.3697, 18.1604, 18.1081, 18.1081, 18.4744, 18.4221, 18.3174,
18.1604, 18.5791, 18.8931, 18.9978, 18.9978, 19.6781, 19.3118,
19.7305, 19.3641, 19.6258, 19.9398, 19.6781, 19.8875, 20.1491,
20.2538, 19.9398, 20.0445, 20.0445, 19.9921, 19.9921, 19.9921,
20.1491, 20.2538, 20.0968, 20.0445, 19.9921, 19.9921, 19.9398,
19.5734, 19.7305, 19.5211, 19.5734, 19.7305, 19.9398, 19.7305,
19.4688, 17.794, 19.2071, 18.5267, 18.4221, 18.6314, 19.0501,
18.9454, 19.1966, 18.9344, 18.7246, 18.5672, 18.0952, 18.0952,
18.0952, 18.0427, 18.3574, 18.2001, 18.4623, 18.3574, 18.3574,
18.0952, 17.7805, 17.6231, 17.6231, 17.9378, 18.0427, 17.7805,
17.5707, 17.6231, 17.9378, 17.8329, 17.4658, 17.256, 17.4133,
17.3084, 18.0427, 18.1476, 18.2525, 18.2001, 18.0952, 18.0427,
17.4658, 17.4133, 17.4133, 17.6231, 17.7805, 17.9378, 18.2001,
18.2001, 18.2001, 18.2525, 17.8329, 18.9344, 18.7246, 18.4099,
18.7246, 18.6197, 18.5148, 18.4623, 18.4099, 18.4099, 18.4623,
18.4099, 18.5148, 18.5148, 18.5148, 18.2001, 17.9903, 18.2001,
17.6756, 18.0952, 18.305, 18.4518, 18.3993, 18.557, 18.925, 18.8724,
18.9775, 19.0827, 18.8724, 18.8724, 18.7673, 18.9775, 18.925,
18.925, 18.6096, 18.7147, 18.8724, 18.8724, 18.8724, 19.0301,
19.1878, 19.4507, 19.0827, 19.4507, 19.3981, 19.6084, 19.6609,
19.8187, 19.7661, 19.0301, 18.5044, 18.6096, 18.6621, 18.4518,
18.5044, 18.7147, 18.3993, 18.189, 18.189, 18.189, 18.4518, 18.6096,
18.9775, 18.8198, 18.3467, 18.189, 18.0839, 18.2416, 18.2416,
18.0839, 18.2416, 18.5044, 18.557, 18.6096, 18.2941, 18.5044,
18.1364, 18.1364, 18.189, 17.9787, 18.189, 18.1364, 18.0839,
17.9262, 17.8736, 17.7684, 17.7579, 17.6525, 17.6525, 17.4945,
17.4418, 17.1783, 17.0202, 16.8621, 16.704, 16.704, 16.8621,
16.8094, 16.4406, 16.4406, 16.2825, 15.8609, 16.3352, 15.9136,
16.4406, 16.3352, 16.1771, 15.7029, 17.7052, 16.8621, 16.8094,
16.8094, 17.0729, 16.9148, 16.3879, 16.546, 17.4418, 17.231,
17.231, 16.8094, 16.9675, 17.1783, 16.8621, 16.6514, 16.3879,
16.3352, 16.5987, 16.3879, 16.3879, 16.6514, 16.019, 15.9136,
15.334, 15.334, 15.0178, 15.1759, 15.0178, 14.9124, 14.8598,
14.7017, 14.5963, 14.7017, 14.4382, 14.5436, 13.964, 14.122,
14.4382, 14.7544, 14.4382, 14.3328, 13.9113, 14.1115, 13.9529,
14.0058, 15.01, 15.01, 15.01, 14.7457, 14.3758, 14.2172, 14.5343,
14.4286, 14.8171, 14.6506, 14.4841, 14.3731, 14.0401, 13.4852,
13.8737, 13.3187, 13.9292, 13.8182, 13.4852, 13.3187)), row.names = c(NA,
-700L), class = c("tbl_df", "tbl", "data.frame"))
Below r1 is the mean of the last 365 rows. (Note that that is what the question asked for but there are not 365 days of data in a year since it seems weekends are missing so this is not the mean of the last year.)
r2 is the mean of the last 365 rows every 30 days. Again I doubt that that is what you wanted even though that is what was asked for.
r3 is the mean of the last 12 months. Presumably this is what you actually need.
Each of these is a zoo object. It is probably best to leave them as zoo objects so you can use the rest of that package easily and not convert them to data frames but if you do want to convert then just use fortify.zoo(r1), etc.
library(zoo)
z <- zoo(data[-1], data[[1]])
r1 <- rollapplyr(z, 365, mean, fill = NA)
r2 <- rollapplyr(z, 365, mean, by = 30, fill = NA)
z.ym <- aggregate(z, as.yearmon, sum)
z.n <- aggregate(z, as.yearmon, length)
r3 <- rollsumr(z.ym, 12, fill = NA) / rollsumr(z.n, 12, fill = NA)
How about this (notice I switched the order of the loops)
If you are iterating over a number:
for (j in 1:498){
for (u in seq(0,5605-30,30))
{
work.on.col = j
work.dt = data[u:u+30,work.on.col] #u:u+30 iterates i.e: 0:30, 30:60,...etc. It only keeps a 30-day rolling window.
}
}
If you are iterating over a date (this would only work if you had your rownames as dates):
for (j in 1:498){
for (u in sapply(seq.Date(as.Date(min(data$Dates)), as.Date(max(data$Dates)),
"day")," [[",30))
{
work.on.col = j
work.dt = data[u:u+30,work.on.col]
}
}

Resources