您好,我在使用reprex的时候出现了问题
otter$time
#> Error in eval(expr, envir, enclos): 找不到对象'otter'
format(strptime(otter$time, format = "%H%M"), format = "%H:%M")
#> Error in strptime(otter$time, format = "%H%M"): 找不到对象'otter'
<sup>Created on 2018-10-23 by the reprex package (v0.2.1)</sup>
但是我运行您的format 代码 得到的结果中存在NA,是因为所有四位数一下的数字都没有转换
抱歉我直接贴上运行结果
otter$time
[1] 840 850 900 910 920 930 940 950 1000 1010 1020 1030 1040 1050 1100 1110 1120 1130 1140 1150 1200
[22] 1210 1220 1230 1240 1250 1300 1310 1320 1330 1340 1350 1400 1410 1420 1430 1440 1450 1500 1510 1520 1530
[43] 1540 1550 1600 1610 1620 1630 1640 1650 1700 1710 1720 1730 1740 1750 1800 1810 1820 1830 1840 1850 1900
[64] 1910 1920 1930 1940 1950 2000 2010 2020 2030 2040 2050 2100 2110 2120 2130 2140 2150 2200 2210 2230 2240
[85] 2250 2300 2310 2320 2330 2340 2350 0 10 20 30 40 50 100 110 120 130 140 150 200 210
[106] 220 230 240 250 300 310 320 330 340 930 940 950 1000 1010 1020 1030 1040 1050 1100 1110 1120
[127] 1130 1140 1150 1200 1210 1220 1230 1240 1250 1300 1310 1320 1330 1340 1350 1400 1410 1420 1430 1440 1450
[148] 1500 1510 1520 1530 1540 1550 1600 1610 1620 1630 1640 1650 1700 1710 1720 1730 1740 1750 1800 1810 1820
[169] 1830 1840 1850 1900 1910 1920 1930 1940 1950 2000 2010 2020 2030 2040 2050 2100 2110 2120 2130 2140 2150
[190] 2200 2210 2220 2230 2240 2250 2300 2310 2320 2330 2340 2350 0 10 20 30 40 50 100 110 120
[211] 130 140 150 200
format(strptime(otter$time, format = "%H%M"), format = "%H:%M")
[1] NA NA NA NA NA NA NA NA "10:00" "10:10" "10:20" "10:30" "10:40"
[14] "10:50" "11:00" "11:10" "11:20" "11:30" "11:40" "11:50" "12:00" "12:10" "12:20" "12:30" "12:40" "12:50"
[27] "13:00" "13:10" "13:20" "13:30" "13:40" "13:50" "14:00" "14:10" "14:20" "14:30" "14:40" "14:50" "15:00"
[40] "15:10" "15:20" "15:30" "15:40" "15:50" "16:00" "16:10" "16:20" "16:30" "16:40" "16:50" "17:00" "17:10"
[53] "17:20" "17:30" "17:40" "17:50" "18:00" "18:10" "18:20" "18:30" "18:40" "18:50" "19:00" "19:10" "19:20"
[66] "19:30" "19:40" "19:50" "20:00" "20:10" "20:20" "20:30" "20:40" "20:50" "21:00" "21:10" "21:20" "21:30"
[79] "21:40" "21:50" "22:00" "22:10" "22:30" "22:40" "22:50" "23:00" "23:10" "23:20" "23:30" "23:40" "23:50"
[92] NA NA NA NA NA NA "10:00" "11:00" "12:00" "13:00" "14:00" "15:00" "20:00"
[105] "21:00" "22:00" "23:00" "00:00" NA NA NA NA NA NA NA NA NA
[118] "10:00" "10:10" "10:20" "10:30" "10:40" "10:50" "11:00" "11:10" "11:20" "11:30" "11:40" "11:50" "12:00"
[131] "12:10" "12:20" "12:30" "12:40" "12:50" "13:00" "13:10" "13:20" "13:30" "13:40" "13:50" "14:00" "14:10"
[144] "14:20" "14:30" "14:40" "14:50" "15:00" "15:10" "15:20" "15:30" "15:40" "15:50" "16:00" "16:10" "16:20"
[157] "16:30" "16:40" "16:50" "17:00" "17:10" "17:20" "17:30" "17:40" "17:50" "18:00" "18:10" "18:20" "18:30"
[170] "18:40" "18:50" "19:00" "19:10" "19:20" "19:30" "19:40" "19:50" "20:00" "20:10" "20:20" "20:30" "20:40"
[183] "20:50" "21:00" "21:10" "21:20" "21:30" "21:40" "21:50" "22:00" "22:10" "22:20" "22:30" "22:40" "22:50"
[196] "23:00" "23:10" "23:20" "23:30" "23:40" "23:50" NA NA NA NA NA NA "10:00"
[209] "11:00" "12:00" "13:00" "14:00" "15:00" "20:00"