我有一个样本数据集如下(Out):
Out <- structure(list(Dist_Out = structure(c(223L, 224L, 195L, 195L,
195L, 235L, 299L, 64L, 336L, 28L, 191L, 129L, 63L, 303L, 249L,
194L, 222L, 177L, 199L, 309L), .Label = c("0", "0.110574578321468",
"0.110574578385818", "0.110574578646219", "0.110574578769975",
"0.110574578837889", "0.110574578901783", "0.110574578961973",
"0.110574579093701", "0.110574579157825", "0.11057457934999",
"0.110574579413902", "0.110574579478479", "0.11057457973394",
"0.110574579798528", "0.11057457999076", "0.110574580247396",
"0.11057458031112", "0.110574580503848", "0.110574580567801",
"0.110574580694844", "0.11057458095289", "0.110574581402704",
"0.110574583204168", "0.111304214830553", "0.111304253300095",
"0.111304307772237", "0.111304317308227", "0.111304330093688",
"0.11130434287376", "0.111304358897914", "0.111304361977123",
"0.11130436522592", "0.111304368417738", "0.11130437160922",
"0.111304371665862", "0.111304374743724", "0.111304374800365",
"0.111304374857007", "0.111304377934532", "0.111304384315138",
"0.11130438437178", "0.111304384428421", "0.111304387561577",
"0.111304390694397", "0.11130439080768", "0.111304393883521",
"0.111304393940163", "0.111304397072309", "0.11130439712895",
"0.111304397185592", "0.111304400317401", "0.111304400374043",
"0.111304403505515", "0.111304403562157", "0.111304413067836",
"0.111304413124478", "0.111304425756241", "0.15689285571989",
"0.156892869769221", "0.15689287418468", "0.156892889774207",
"0.156892912024679", "0.156892934292016", "0.156892940915204",
"0.156892943136249", "0.156892949836902", "0.156892951976477",
"0.156892954196025", "0.156892954236129", "0.156892954236208",
"0.156892954276312", "0.156892955820879", "0.156892955820883",
"0.156892955861062", "0.156892955861066", "0.156892958674593",
"0.156892958714776", "0.156892958714863", "0.156892960893118",
"0.156892960893133", "0.156892960933301", "0.156892960933317",
"0.156892962437304", "0.156892962437361", "0.156892962477487",
"0.156892962477544", "0.156892962517727", "0.156892969726529",
"0.156892969766712", "0.15689296976675", "0.156892969806895",
"0.156892971984017", "0.156892971984051", "0.1568929720242",
"0.156892972024234", "0.156892974161436", "0.156892974201513",
"0.156892974201619", "0.156892974241696", "0.156892974241802",
"0.156892975744282", "0.156892975824626", "0.156892978001093",
"0.156892978001154", "0.156892980852422", "0.156892980892616",
"0.156892983068896", "0.156892983109079", "0.156892989757201",
"0.156892991892444", "0.156892991892504", "0.15689299197287",
"0.156892994188015", "0.156892995093831", "0.15689299509388",
"0.156892998578116", "0.221149157095331", "0.221149157735701",
"0.221149158248122", "0.221149158251639", "0.221149158504029",
"0.221149158760615", "0.221149158892054", "0.221149159532802",
"0.221149160045349", "0.221149161071762", "0.221149161712213",
"0.22114916222707", "0.222608333407496", "0.22260837837114",
"0.222608384735182", "0.222608455374887", "0.222608493783746",
"0.222608596296507", "0.222608692192514", "0.222608730508481",
"0.222608736835477", "0.222608736892118", "0.222608768800201",
"0.222608794314542", "0.222608800691444", "0.222608857996604",
"0.247579423347402", "0.247579452035982", "0.247579496248119",
"0.247579500729161", "0.24757950684186", "0.247579510261327",
"0.247579510261392", "0.247579513391942", "0.247579513417395",
"0.247579513417407", "0.247579513442859", "0.247579516860718",
"0.247579518205451", "0.247579519185166", "0.247579519236095",
"0.247579525289911", "0.247579525315375", "0.24757952875664",
"0.247579529784064", "0.248558365959636", "0.248558423080156",
"0.248558474437371", "0.2485585599757", "0.248558577056858",
"0.248558611101923", "0.248558622479214", "0.24855862258067",
"0.248558628217488", "0.248558650962925", "0.248558656698174",
"0.248558662331659", "0.313785772234975", "0.313785790083671",
"0.313785798944933", "0.313785861163643", "0.313785884051598",
"0.313785919567943", "0.313785932204374", "0.313785932284703",
"0.31378593228474", "0.313785941750578", "0.313785949945705",
"0.313785953785589", "0.313785958853473", "0.313785958853573",
"0.331723736573009", "0.331723737017998", "0.331723741058604",
"0.331723747874274", "0.33172374819982", "0.333912827211437",
"0.333912980750125", "0.333913067001972", "0.333913133973521",
"0.349898963305821", "0.349898967518276", "0.349898985849967",
"0.349898989161391", "0.349898989161427", "0.349898997505614",
"0.349898997505615", "0.351744805744357", "0.351744887722199",
"0.351745133189943", "0.351745187980364", "0.3517453055621",
"0.35174531490497", "0.351745323909966", "0.399493757974483",
"0.399493788597454", "0.399493795359845", "0.399493832734277",
"0.399493843627049", "0.399493845554748", "0.400505368728602",
"0.400505423976401", "0.400505448284272", "0.400505527258931",
"0.400505598712409", "0.400505694328303", "0.400505709727528",
"0.400505725573516", "0.400505765671134", "0.40050589965877",
"0.400505923319168", "0.442298314835368", "0.442298317140206",
"0.442298324709909", "0.442298327797584", "0.445216846546918",
"0.445217192536371", "0.445217307591311", "0.445217345994231",
"0.445217512021335", "0.456088216475352", "0.456088223195701",
"0.458742575215647", "0.45874273685115", "0.458742885695134",
"0.458742910728267", "0.458743282342636", "0.470678474711803",
"0.47067880878535", "0.470678942002923", "0.495158931652482",
"0.495158944897039", "0.497116508401871", "0.49711679476651",
"0.49711679476653", "0.497116851569911", "0.497116897580156",
"0.554189163095155", "0.55418920215693", "0.554189262709751",
"0.554189324595007", "0.555210390817594", "0.555210746638391",
"0.556520945842888", "0.556521218492923", "0.556521458662341",
"0.563965519478444", "0.567399619528133", "0.567399713876817",
"0.567399933968277", "0.567399934023851", "0.567400184553882",
"0.596005878229009", "0.59600588239606", "0.598851042068279",
"0.598851279385347", "0.59885148700117", "0.627571384004223",
"0.627571616364075", "0.645883965371449", "0.645884171696778",
"0.64588421378803", "0.6478858784372", "0.647886220479167", "0.647886397912576",
"0.663447495427633", "0.667825269848697", "0.667825558298464",
"0.676917586632606", "0.676917795416644", "0.676918079344979",
"0.676918476303909", "0.703489456836576", "0.703489456890362",
"0.703490602009756", "0.709849619231796", "0.709850031391416",
"0.710875054488227", "0.745675302791038", "0.745675354954646",
"0.74567545723098", "0.745675662288711", "0.774022055439241",
"0.779129683432762", "0.779130802335089", "0.784464537327535",
"0.784464615110459", "0.786936919065818", "0.801010975018698",
"0.809907498350714", "0.809907713628001", "0.846808290999277",
"0.846808722035823", "0.866982968100186", "0.866983288894348",
"0.897273124467317", "0.897273302678894", "0.897273328167299",
"0.897273404335645", "0.917485187536906", "0.917485560660896",
"0.917485808994169", "0.955359158283399", "0.955359809834417",
"0.994234273564382", "1.0017384527634", "1.00782274966041", "1.0233303727427",
"1.09503832959811", "1.09503864342042", "1.09825019601709", "1.12793099939348",
"1.14021123855837", "1.24279165758788", "1.2441584622863", "1.25514264374951",
"1.2638862424017", "1.34543853012779", "1.44555679702924", "1.45117535398978",
"1.59180424399744", "1.66256690191307", "1.7271568926302", "1.79454617273675",
"1.83497057428696", "3.07757525439021"), class = "factor"), Speed_Out = structure(c(2L,
8L, 8L, 4L, 15L, 15L, 6L, 15L, 17L, 8L, 8L, 10L, 23L, 25L, 17L,
11L, 8L, 8L, 9L, 8L), .Label = c("0", "0.03", "0.06", "0.09",
"0.095", "0.12", "0.125", "0.155", "0.185", "0.19", "0.215",
"0.22", "0.245", "0.25", "0.275", "0.28", "0.31", "0.34", "0.345",
"0.37", "0.375", "0.4", "0.405", "0.435", "0.465", "0.495", "0.5",
"0.525", "0.555", "0.62", "0.715", "0.745", "0.775", "0.965",
"1.085", "1.12"), class = "factor"), Acceleration_Out = structure(c(20L,
25L, 6L, 20L, 28L, 9L, 19L, 28L, 7L, 2L, 21L, 19L, 31L, 9L, 19L,
6L, 21L, 2L, 23L, 6L), .Label = c("-0.012", "-0.014", "-0.024",
"-0.026", "-0.036", "-0.038", "-0.048", "-0.05", "-0.062", "-0.074",
"-0.076", "-0.088", "-0.1", "-0.112", "-0.138", "-0.162", "-0.222",
"-0.286", "0", "0.012", "0.014", "0.024", "0.026", "0.036", "0.038",
"0.048", "0.05", "0.062", "0.074", "0.076", "0.086", "0.088",
"0.1", "0.112", "0.124", "0.162", "0.222", "0.286"), class = "factor"),
Absolute_Heading_Out = structure(c(113L, 114L, 166L, 275L,
275L, 273L, 121L, 211L, 260L, 288L, 1L, 1L, 92L, 213L, 134L,
274L, 22L, 54L, 74L, 183L), .Label = c("0", "104.038094380956",
"104.038099175016", "104.038100287972", "104.038104254506",
"104.933371095486", "108.437291746436", "108.437292238906",
"108.437292594443", "108.437321740952", "111.804138048148",
"113.201423738397", "113.965388161297", "116.568179327572",
"116.568179982698", "116.568185226911", "116.568202500823",
"116.568207149774", "123.693672004617", "123.693687366444",
"123.693691078493", "123.693703315054", "123.693711549325",
"126.873674566913", "130.605207664786", "135.003902542311",
"135.00390464519", "135.003904674347", "135.003905470793",
"135.003907948238", "135.003907962816", "135.003908259113",
"135.003908774132", "135.003908968467", "135.003910222254",
"135.003911252625", "135.003911281782", "135.003911680336",
"135.003912078869", "135.003912905428", "135.003912920006",
"135.003912934585", "135.00391516638", "135.003915180958",
"135.00391581295", "135.003916226374", "135.003917038677",
"135.003917053256", "135.003918707167", "135.003919548889",
"135.003920346791", "135.003922843585", "135.003923671108",
"135.003938050425", "135.003939340192", "135.003948537839",
"135.003950183691", "135.0039588283", "14.0343965682479",
"14.0344008293472", "141.344008995685", "146.313535791806",
"146.313537999457", "153.438076376928", "153.438078534744",
"153.438079763631", "153.438085623885", "153.43812488595",
"161.567394954315", "161.567399368491", "180", "191.30841097092",
"198.432585234004", "198.432587185674", "198.432598104786",
"201.798689939092", "206.561897223892", "206.561914376115",
"206.561918159163", "206.561920224708", "206.561923646396",
"210.960297150126", "213.686445206476", "213.686465120369",
"216.866121212474", "216.866126783458", "218.655948156729",
"224.99604368852", "224.996057271547", "224.9960602985",
"224.99606521108", "224.996065562981", "224.996081278255",
"224.99608235309", "224.996082367668", "224.996082946744",
"224.996083788204", "224.996084848199", "224.996086776282",
"224.996086790861", "224.996087079994", "224.996087906553",
"224.996088732797", "224.996089777746", "224.996090081518",
"224.996090618394", "224.996094529207", "224.996097816515",
"230.190571318522", "231.336326241386", "234.458609341892",
"236.306289792777", "236.306305752159", "236.306307393042",
"236.306325713134", "239.032745245313", "239.032773084164",
"243.431791522707", "243.431797625395", "243.431808769598",
"243.431811475523", "245.221858182135", "251.562680070773",
"251.56268455414", "251.562697978643", "251.562700819679",
"254.052524049611", "255.961907894589", "255.961909409804",
"255.961917967213", "257.469536195034", "258.68855355037",
"258.688558827016", "26.561897224065", "26.561909979624",
"26.5619152872187", "26.5619165055352", "26.561920485388",
"26.5619245326763", "26.5619257724073", "260.536399738673",
"262.874018076851", "262.87401868698", "263.658950185096",
"270.000000825397", "270.000000825739", "270.000000825967",
"270.000000826081", "270.000000826195", "270.000000826309",
"270.000000826423", "270.000000826651", "270.000000826765",
"270.000000826878", "270.000000826879", "270.00000082722",
"270.000000827562", "270.00000165051", "270.000001652902",
"270.000001653814", "270.000001657631", "270.000001661505",
"270.000001663556", "270.000001664809", "270.000002479914",
"270.000002484092", "270.000003306546", "270.000003311075",
"270.000003315262", "270.000004144966", "270.000004158936",
"270.000004979198", "270.000005782192", "270.000007465657",
"277.125995411424", "277.125996790413", "277.126003803657",
"281.311454747624", "284.038107767959", "288.437300278551",
"29.0512461969053", "291.804137106086", "293.201447869319",
"296.568183955338", "296.568186601703", "296.568187257637",
"296.568187269301", "296.568188593043", "296.568211697749",
"296.568217115325", "296.568231666689", "30.9602599760489",
"30.9602987561062", "303.693725157126", "315.003904193081",
"315.003905470703", "315.003906325462", "315.003910440718",
"315.003911033758", "315.003911563215", "315.003911845393",
"315.003912005172", "315.003913746145", "315.003914572848",
"315.003916515341", "315.003917865386", "315.003917879964",
"315.00391928621", "315.003919300789", "315.003925739793",
"315.003927795227", "315.003929770525", "315.00394101503",
"315.003946345431", "315.003956610649", "322.128861928285",
"323.133860711499", "323.13386938527", "323.133916640514",
"326.313549702075", "33.6864487776922", "333.438072719985",
"333.438075455662", "333.438081405064", "333.438081416726",
"333.438112671245", "338.201312240365", "341.567396605941",
"341.567401021678", "348.691571595965", "350.538959809096",
"44.9960299262225", "44.9960433893507", "44.9960647858047",
"44.9960714405142", "44.9960796387537", "44.9960796533323",
"44.9960813075886", "44.9960821346143", "44.996083165653",
"44.9960831802316", "44.9960854271517", "44.9960862684335",
"44.9960870802999", "44.9960870948785", "44.9960889662424",
"50.1905434337506", "53.1262908803736", "54.4585694603986",
"56.3062693546384", "56.3062770335264", "59.032755274607",
"63.4317723208886", "63.4317848802781", "63.4317895372392",
"63.4317935836423", "63.4317955060977", "63.4318074457203",
"66.0345895371247", "67.3773348964212", "68.1958709110713",
"71.562668281165", "74.052516819087", "75.9618996568146",
"78.6885389399677", "78.6885408616536", "79.6937487439011",
"85.6006837571501", "89.9999941872715", "89.9999950129589",
"89.9999958484933", "89.9999966753091", "89.9999966878713",
"89.9999975116924", "89.9999975159082", "89.999997518263",
"89.9999983366149", "89.9999983395774", "89.9999983449896",
"89.9999983460151", "89.999998346186", "89.9999983470975",
"89.9999983477812", "89.9999983479521", "89.9999991689056",
"89.9999991699311", "89.9999991714124", "89.9999991716402",
"89.9999991719821", "89.9999991728936", "89.9999991730076",
"89.9999991731215", "89.9999991732354", "89.9999991735772",
"89.9999991735773", "89.9999991736912", "89.9999991738051",
"89.9999991739191", "89.999999174033", "89.9999991742609",
"98.1312035976929", "99.4635877243328", "99.4635933528321",
"99.4635973787254"), class = "factor"), Relative_Heading_Out = structure(c(84L,
3L, 120L, 273L, 213L, 403L, 38L, 180L, 297L, 73L, 409L, 213L,
74L, 210L, 326L, 166L, 121L, 10L, 162L, 212L), .Label = c("-1.08941367216175e-06",
"-1.27762228885331e-06", "-1.64088351084501e-06", "-1.97529777778982e-06",
"-10.6207232354447", "-107.098299845166", "-108.432605871424",
"-11.3096297403433", "-11.3102336441757", "-11.3102347353711",
"-11.3114558136556", "-11.3114593966472", "-11.6348360542887",
"-110.383710239579", "-111.798690769161", "-116.561876778859",
"-116.568179982698", "-119.048575511772", "-12.5275134113761",
"-125.54290253755", "-126.873674566913", "-134.996083788201",
"-134.99608874744", "-135.003907962816", "-135.003910222254",
"-135.003910440718", "-135.003912920006", "-135.003916226374",
"-135.003917053256", "-135.003920346791", "-14.0343965682479",
"-14.0344008293472", "-14.0381027887613", "-14.9333752469922",
"-15.2563802581807", "-151.923815028848", "-153.431797335435",
"-153.431814787652", "-153.438076376928", "-153.438078534744",
"-153.438081405064", "-155.224175835841", "-16.5895970517398",
"-161.564269704982", "-161.564270216045", "-163.070873427349",
"-168.688559655604", "-173.087896236407", "-178.210035361013",
"-18.4357312990837", "-18.4357320431515", "-18.4357376166744",
"-18.4372944963587", "-18.4373234043367", "-18.4374360606442",
"-180", "-180.00000165239", "-180.000001652846", "-180.000001653188",
"-180.00000165359", "-180.000001653757", "-189.462544556087",
"-19.440191483388", "-191.310236746892", "-198.432598104786",
"-198.435737329084", "-201.804133233895", "-203.197372900173",
"-206.561923646396", "-213.686445206476", "-213.693730144167",
"-216.866121212474", "-22.6226642752191", "-224.996065562981",
"-224.996082946744", "-224.996084848199", "-224.996086776282",
"-224.996090081518", "-225.003911859839", "-225.003915399271",
"-225.003918706729", "-23.2014262201339", "-235.306909073552",
"-236.306305752159", "-24.2299694795691", "-243.438082243148",
"-251.562697978643", "-251.572156808192", "-26.561920485388",
"-26.5619245326763", "-26.5682154538194", "-270.000000825739",
"-270.000000826081", "-270.000000826195", "-270.000000826423",
"-270.00000082722", "-270.00000165051", "-270.000001652902",
"-270.000001663556", "-270.000005782192", "-270.007837978621",
"-278.137789746516", "-296.568183955338", "-296.568186601703",
"-30.9658311909307", "-30.9672302310985", "-315.003904193081",
"-315.003911033758", "-315.003911845393", "-315.003912005172",
"-315.003913746145", "-315.003914572848", "-315.003916515341",
"-315.003917865386", "-315.00391928621", "-322.128861928285",
"-322.129645823558", "-326.313549702075", "-33.6864487776922",
"-33.6936950910497", "-33.6937058033612", "-33.6937221353792",
"-333.438075455662", "-341.567396605941", "-36.8661267834578",
"-36.8698974613882", "-38.6636779175493", "-4.39902960567105",
"-4.63602950075966", "-40.6024036695531", "-44.99604368852",
"-44.9960796387537", "-44.9960812782547", "-44.9960812928333",
"-44.9960821346143", "-44.996083165653", "-44.9960831802316",
"-44.9960837736256", "-44.9960862684335", "-44.9960870799939",
"-44.9960870802999", "-44.9960920371838", "-44.9960945292073",
"-45.0039062965318", "-45.0039099113321", "-45.0039104261803",
"-45.0039137610075", "-45.0039159931442", "-45.0039170385072",
"-45.0039170385603", "-45.0039184592101", "-45.0039195195613",
"-45.0039195342731", "-45.0039244841527", "-45.0039501982616",
"-49.2730539449748", "-50.1905434337506", "-50.5335956897864",
"-56.3063089215069", "-56.3135357050287", "-6.55934059068386e-07",
"-63.4286491352498", "-63.4317895372392", "-63.438071894588",
"-63.4380797638232", "-63.4381002876273", "-63.4381102417655",
"-66.7985762616031", "-69.0799574007877", "-69.2279887677529",
"-69.782098428514", "-7.01324449892127e-06", "-7.76602933812626",
"-71.5579915325294", "-71.5580050437492", "-71.5626782590484",
"-71.5674001952552", "-71.5674035490282", "-71.5720922472722",
"-71.5721163197041", "-71.5721653034134", "-78.6825596495758",
"-8.12994870632622", "-8.13108046273612", "-8.26243820029049e-07",
"-8.26479720217321e-07", "-8.26631662675936e-07", "-8.26992447855446e-07",
"-8.54759605317668e-07", "-81.8643827331808", "-82.8740180768513",
"-89.9921636459231", "-89.9921690352491", "-89.9921952742039",
"-89.999998346186", "-89.9999991719821", "-89.9999991731215",
"-89.9999991732354", "-89.9999991735772", "-89.9999991736912",
"-89.9999991738051", "-89.9999991739191", "-90.000000825967",
"-90.0000008260809", "-90.0000008264228", "-90.0000008267646",
"-90.0000008268785", "-90.0000008280179", "-90.0000033110747",
"-90.0078754520491", "-90.0079289020773", "-94.7688606836447",
"0", "1.21831646993087e-06", "1.6576310599703e-06", "1.66235020060412e-06",
"101.302350452585", "106.496883952078", "108.427537580527",
"108.44197890194", "11.3096332494953", "11.3102394284159",
"11.3113335227112", "11.3114583072521", "116.561916857852",
"116.56192105113", "116.568187269301", "117.402527859642",
"12.2476780128984", "120.957965917544", "125.532495222411",
"132.268196345264", "134.996085645806", "134.996087906417",
"134.996090907599", "135.00390464519", "135.003907948238",
"135.003910222254", "135.003911252625", "135.003911281782",
"135.003911680336", "135.003912905428", "135.003912920006",
"135.003912934585", "135.00391516638", "135.00391928621",
"135.003919548889", "14.0344008293472", "143.130106780739",
"15.2567559249757", "153.433391310084", "153.438081405064",
"153.438085623885", "161.562685384209", "161.564271367631",
"161.564271627437", "161.565836751711", "18.4341646234914",
"18.4341666601178", "18.4341668582031", "18.4341672821188",
"18.4357306931675", "18.4357346476826", "18.4357360052061",
"18.435740353848", "18.4372930648732", "18.8010696166384",
"180", "180.000001651478", "180.00000165239", "180.000001652497",
"180.000001652846", "180.000004968184", "187.12599956293",
"187.695688180681", "19.5660942200254", "191.309633889126",
"194.038104488152", "198.432585234004", "2.20765036829107e-06",
"201.804138766508", "206.561920224708", "206.561923646396",
"206.566618439315", "206.568189420149", "21.1640959090685",
"213.693732308918", "222.278699473017", "224.99608235309",
"224.996086790861", "224.996089777746", "224.996097816515",
"225.00391951929", "225.003920954773", "229.769652363221",
"243.431808769598", "247.626592898806", "251.567401848443",
"251.572173725974", "255.961909409804", "26.561909979624",
"26.5619143761148", "26.5619152872187", "26.561918159163",
"26.561920485388", "26.5619245326763", "26.5634850427263",
"26.5656849738252", "26.5666170276959", "26.5674578635275",
"26.5681908992693", "270.000000825739", "270.000000825967",
"270.000000826081", "270.000000826195", "270.000000826423",
"270.000000826651", "270.000000826765", "270.000000826879",
"270.00000082722", "270.000000827562", "270.00000165051",
"270.000001657631", "270.007821474476", "270.007864984721",
"288.442043790965", "3.5553682664613e-07", "3.96653496181898e-06",
"30.9602599760489", "30.9658300606604", "30.9658510086751",
"30.967256419496", "315.003906325462", "315.003911033758",
"315.003913746145", "315.003916515341", "315.003917865386",
"315.003917879964", "33.6864487776922", "33.6936728303563",
"33.6937173620532", "33.6941930107691", "333.438072719985",
"333.438075455662", "333.438081416726", "348.691571595965",
"350.538959809096", "38.0930036092936", "38.6628898865961",
"4.26803802337022", "40.6024008285175", "44.9960829613228",
"44.9960831802316", "44.9960848481989", "44.9960862684335",
"44.9960870799939", "44.9960870802999", "44.9960870948785",
"44.9960879211313", "44.9960906183937", "44.9960920517623",
"44.9960945292073", "45.0039102076872", "45.0039106205144",
"45.0039107371338", "45.0039110191976", "45.003911048449",
"45.0039137464255", "45.0039137464256", "45.0039165156846",
"45.0039195196753", "45.0039249122307", "45.0039253261187",
"49.579530827573", "58.6778036558414", "6.34009731534894",
"6.34105728056107", "63.4380772030091", "63.4380789368118",
"63.4380805900751", "63.438083494651", "63.4381110097399",
"63.4412765398765", "63.4412905471348", "64.6593257332515",
"66.0346118387025", "68.2013072611666", "7.12550172992948",
"7.76603379364138", "7.96445306150417e-07", "7.97902600879752e-07",
"71.5626800707728", "71.5627008196788", "71.5720922326936",
"74.052516819087", "74.7389307588194", "78.682521535368",
"78.6885588270165", "78.6915931880158", "8.12994364547711",
"8.12994419615723", "8.26137920739711e-07", "8.28036945677013e-07",
"83.0050894051913", "85.2304874382689", "87.5169609528689",
"89.9921898840171", "89.999998346186", "89.9999991716402",
"89.9999991731215", "89.9999991732354", "89.9999991735772",
"89.9999991736912", "89.9999991738051", "89.9999991739191",
"89.999999174033", "89.9999991742609", "9.46359418141975",
"90.0000008260809", "90.0000008261949", "90.0000008263088",
"90.0000008264227", "90.0000008264228", "90.0000008267646",
"90.0000008268785", "90.0000016529025", "93.1724357049647"
), class = "factor"), Movement_Out = structure(c(2L, 1L,
1L, 3L, 3L, 3L, 2L, 3L, 4L, 1L, 3L, 3L, 3L, 2L, 4L, 2L, 1L,
3L, 3L, 2L), .Label = c("forward", "left", "non-moving",
"right"), class = "factor"), Changes_Out = structure(c(1L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 1L, 2L), .Label = c("0", "1"), class = "factor"),
AccPosNeg_Out = structure(c(2L, 2L, 1L, 2L, 2L, 1L, 2L, 2L,
1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), .Label = c("0",
"1"), class = "factor"), AccChange_Out = structure(c(2L,
1L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c("0", "1"), class = "factor")), .Names = c("Dist_Out",
"Speed_Out", "Acceleration_Out", "Absolute_Heading_Out", "Relative_Heading_Out",
"Movement_Out", "Changes_Out", "AccPosNeg_Out", "AccChange_Out"
), row.names = c(NA, 20L), class = "data.frame")
以及以下功能:
JRip <- function (Dist_Out, Speed_Out, Acceleration_Out, Absolute_Heading_Out,
Relative_Heading_Out, Movement_Out, Changes_Out, AccPosNeg_Out,
AccChange_Out)
{
if (max(Speed_Out) >= 2.45) {
Behaviour <- "walking"
}
else if (mean(Acceleration_Out[Acceleration_Out > 0]) >=
0.03 & (max(Dist_Out[Movement_Out != "non-moving"]) <=
2.17 & (mean(Speed_Out) >= 0.23 & (sum(Dist_Out[Movement_Out !=
"non-moving"]) >= 11.92)))) {
Behaviour <- "grazing"
}
else Behaviour <- "resting"
return(Behaviour)
}
我想分析5个实例的段中的数据集,然后分析到接下来的5个实例,并再次应用此函数。因此对于20个实例的这个数据集,我期望来自该函数的4个预测。似乎逻辑上要做的是在数据集上传递一个滑动窗口 - 经过多次试验并最终意识到rollapply不会采用混合类型,我想知道是否可以使用for循环完成此操作?该函数使用均值和最大值,虽然我尝试了很多for循环但我无法使其工作。有谁知道如何编写for循环来实现这一目标?
答案 0 :(得分:3)
首先,您需要将数据转换为数字类型,因为它们存储为因子:
Out[,-6] <- as.data.frame(sapply(Out[,-6], function(x) as.numeric(as.character(x))))
现在,您可以使用split-apply-combine将数据框分成5行块,将函数应用于每个,并获取结果:
sapply(split(Out, rep(1:4, each=5)), do.call, what=JRip)
# 1 2 3 4
# "resting" "resting" "resting" "resting"
对于提供的数据框,看起来每个5行段都处于静止状态。这很容易确认,因为max(Out$Speed_Out)
是0.465,意味着没有分段行走,而sum(Out$Dist_Out)
是8.94,这意味着没有分段正在放牧。