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

跟風遠走 提交于 2019-12-18 19:00:29

问题


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)

回答1:


And even shorter:

v <- na.omit(v)



回答2:


Try this:

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



回答3:


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 :)



来源:https://stackoverflow.com/questions/13313704/how-to-remove-na-values-in-vector-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!