Error calculating the distance between values from a data.frame - r
I'm trying to calculate the distance between different points that are a subset from a data.frame.
The method I try to use is distHaversine from library geosphere.
I have my data in var st and try using the function such as:
distHaversine(st[1,c(3,2)],st[2,c(3,2)])
Where each row in st is an entry of a new place, column 3 is longitude and column 2 is latitude.
Using the function in this manner gives me the following error:
Error in .pointsToMatrix(p1) * toRad :
non-numeric argument to binary operator
Reading the error something like:
distHaversine(as.double(st[1,c(3,2)]),as.double(st[2,c(3,2)]))
sounds like it should solve the problem but that just gives med another error:
Error in .pointsToMatrix(p1) : latitude > 90
If I manually add the lat and long in to the function such as:
distHaversine(c(12.6959,60.3097),c(12.6959,60.3097))
It works and returns 0.
The output of st[1,c(3,2)] and st[2,c(3,2)] is the following:
longitude latitude
1 12.6959 60.3097
longitude latitude
2 12.6959 60.3097
Output of dput(st[1:2, 2:3]):
structure(list(latitude = structure(c(422L, 422L), .Label = c(" latitude",
"55.3376", "55.3836", "55.3838", "55.384", "55.3872", "55.4114",
"55.441", "55.47411", "55.4889", "55.4907", "55.5", "55.5231",
"55.5449", "55.597", "55.6048", "55.6049", "55.6093", "55.6333",
"55.6402", "55.65", "55.6646", "55.693", "55.7", "55.7142", "55.7833",
"55.8633", "55.8666", "55.8798", "55.9", "55.9033", "55.9081",
"55.9245", "55.9557", "55.9833", "56.0131", "56.0133", "56.02391",
"56.0304", "56.0419", "56.0431", "56.05", "56.0666", "56.0699",
"56.07", "56.0752", "56.1333", "56.1498", "56.1813", "56.1957",
"56.1977", "56.2", "56.2182", "56.2287", "56.2451", "56.2619",
"56.2799", "56.2979", "56.3012", "56.3666", "56.38", "56.40404",
"56.4495", "56.45", "56.4595", "56.4782", "56.5124", "56.5177",
"56.5256", "56.5376", "56.5546", "56.5684", "56.601", "56.6166",
"56.6333", "56.66694", "56.67", "56.6737", "56.675", "56.6784",
"56.6833", "56.7154", "56.727", "56.7429", "56.7486", "56.7849",
"56.823", "56.8311", "56.8403", "56.8427", "56.8464", "56.8526",
"56.8666", "56.8865", "56.8994", "56.9213", "56.9222", "56.9252",
"56.9303", "56.931", "56.9496", "56.9628", "56.9835", "57.0333",
"57.0666", "57.0735", "57.1084", "57.1088", "57.1136", "57.11667458",
"57.121", "57.1461", "57.1462", "57.1484", "57.1834", "57.1978",
"57.2001", "57.2166", "57.2323", "57.2438", "57.253", "57.2577",
"57.2674", "57.2833", "57.2847", "57.288", "57.2893", "57.3025",
"57.304", "57.3672", "57.3689", "57.3848", "57.3908", "57.3915",
"57.4034", "57.4042", "57.4166", "57.4208", "57.4413", "57.45",
"57.4666", "57.4833", "57.485", "57.4983", "57.4998", "57.54361",
"57.5571", "57.5653", "57.5666", "57.596", "57.6295", "57.6324",
"57.636", "57.642", "57.6431", "57.6468", "57.661", "57.6614",
"57.6678", "57.6687", "57.6898", "57.7071", "57.7084", "57.7166",
"57.7213", "57.722", "57.7242", "57.75", "57.7514", "57.7611",
"57.7666", "57.7786", "57.7848", "57.7865", "57.8052", "57.8232",
"57.8305", "57.8425", "57.8429", "57.85", "57.8701", "57.8748",
"57.8863", "57.8887", "57.8987", "57.9166", "57.9167", "57.93309233",
"57.936", "57.9666", "58.0067", "58.0166", "58.0201", "58.03",
"58.0333", "58.0389", "58.0492", "58.0582", "58.0718", "58.0729",
"58.0788", "58.0794", "58.0908", "58.094", "58.0944", "58.0951",
"58.1425", "58.1584", "58.1589", "58.19969", "58.19981831", "58.2",
"58.2148", "58.2159", "58.2212", "58.2333", "58.2502", "58.2505",
"58.2662", "58.288", "58.2886", "58.3", "58.3141", "58.3221",
"58.3331352", "58.3333", "58.3339", "58.3476", "58.355", "58.3552",
"58.3571", "58.37", "58.38", "58.3833", "58.3928", "58.3935",
"58.3943", "58.3949", "58.4", "58.4004", "58.4072", "58.4166",
"58.4274", "58.4358", "58.4397", "58.4447", "58.4529", "58.4666",
"58.472", "58.5166", "58.5185", "58.5289", "58.5491", "58.55",
"58.5586", "58.5707", "58.5719", "58.5763", "58.5833", "58.5842",
"58.5929", "58.60033", "58.606", "58.6068", "58.6082", "58.6277",
"58.6336", "58.6493", "58.65", "58.66076", "58.6777", "58.6894",
"58.6998", "58.7104", "58.7136", "58.7165", "58.7333", "58.7421",
"58.7433", "58.7588", "58.7833", "58.78468", "58.7904", "58.7906",
"58.7936", "58.8", "58.8055", "58.8063", "58.8333", "58.85",
"58.8509", "58.8772", "58.88", "58.8925", "58.898", "58.9", "58.904",
"58.9333", "58.9334", "58.9502", "58.9671", "58.9733", "58.9817",
"59.0185", "59.0297", "59.05", "59.0542", "59.0561", "59.0666",
"59.0667", "59.0688", "59.08304351", "59.0833", "59.0966", "59.1166",
"59.1412", "59.1469", "59.1547", "59.1789", "59.182", "59.1833",
"59.2032", "59.2184", "59.2217", "59.2289", "59.2333", "59.2334",
"59.2361", "59.2448", "59.2511", "59.2661", "59.2671", "59.2782",
"59.2833", "59.2891", "59.2901", "59.2996", "59.3", "59.3107",
"59.3226", "59.342", "59.3421", "59.35", "59.3537", "59.3582",
"59.361", "59.3619", "59.3658", "59.3832", "59.3833", "59.384",
"59.3867", "59.3868", "59.4", "59.402", "59.4166", "59.4428",
"59.4445", "59.4446", "59.5052", "59.5171", "59.5345", "59.55",
"59.5737", "59.5833", "59.5976", "59.6072", "59.6112", "59.6166",
"59.6269", "59.6396", "59.6557", "59.6575", "59.6616", "59.6658",
"59.6747", "59.6833", "59.7166", "59.7497", "59.75", "59.7506",
"59.7534", "59.8085", "59.8139", "59.8321", "59.8333", "59.85",
"59.8524", "59.8585", "59.8586", "59.8633", "59.8644", "59.8707",
"59.8709", "59.88", "59.8953", "59.9045", "59.9098", "59.9268",
"59.9445", "59.95", "60.0666", "60.0991", "60.1075", "60.1197",
"60.12295", "60.1419", "60.1426", "60.1514", "60.1538", "60.1595",
"60.169", "60.175", "60.2", "60.2026", "60.2357", "60.2363",
"60.2688", "60.2761", "60.2788", "60.3", "60.3097", "60.3328",
"60.3333", "60.3548", "60.3758", "60.3822", "60.4294", "60.4393",
"60.4551", "60.4889", "60.5", "60.502", "60.5074", "60.5262",
"60.5333", "60.542", "60.55", "60.6046", "60.6103", "60.619",
"60.651", "60.6537", "60.6717", "60.6773", "60.7004", "60.7166",
"60.7256", "60.7304", "60.7547", "60.75686", "60.8321", "60.88",
"60.8846", "60.9066", "60.923", "60.9607", "60.962", "60.9645",
"60.9676", "61.0025", "61.0442", "61.0666", "61.1269", "61.15829",
"61.1666", "61.1691", "61.1766", "61.2542", "61.2555", "61.2691",
"61.2797", "61.3198", "61.3613", "61.3784", "61.3882", "61.395",
"61.4446", "61.5", "61.55", "61.6022", "61.6239", "61.6408",
"61.6577", "61.6606", "61.6912", "61.7027", "61.7033", "61.7111",
"61.7167", "61.7854", "61.8271", "61.8333", "61.85", "61.8526",
"61.8547", "61.8691", "61.8892", "62.0166", "62.0291", "62.0424",
"62.0471", "62.0943", "62.0991", "62.1132", "62.1299", "62.1809",
"62.2207", "62.2314", "62.26317", "62.3809", "62.4066", "62.4112",
"62.4172", "62.43064", "62.4502", "62.4943", "62.4961", "62.5",
"62.5165", "62.5166", "62.5246", "62.5335", "62.5493", "62.5772",
"62.6183", "62.628", "62.6431", "62.65", "62.72909", "62.7503",
"62.7512", "62.7557", "62.7594", "62.76291", "62.8016", "62.8108",
"62.8166", "62.8485", "62.9948", "63.0335", "63.044", "63.0447",
"63.05", "63.0502", "63.0509", "63.0796", "63.1251", "63.1333",
"63.1466", "63.1521", "63.1618", "63.16629", "63.1667", "63.1736",
"63.1864", "63.1885", "63.1886", "63.1947", "63.1974", "63.2443",
"63.2631", "63.2831", "63.3028", "63.30543", "63.3158", "63.3166",
"63.3193", "63.3266", "63.3269", "63.37375", "63.3806", "63.4",
"63.4119", "63.4304", "63.4359", "63.4608", "63.5739", "63.5949",
"63.595", "63.6198", "63.6513", "63.6574", "63.677", "63.6849",
"63.6968", "63.7", "63.73", "63.7606", "63.7695", "63.7788",
"63.7947", "63.8082", "63.8129", "63.8302", "63.8395", "63.8548",
"63.8683", "63.9187", "63.925", "63.9515", "63.9687", "63.9812",
"63.9967", "64.0432", "64.0753", "64.0763", "64.0885", "64.1236",
"64.159", "64.1661", "64.1973", "64.2", "64.2182", "64.2684",
"64.2734", "64.3636", "64.4309", "64.43583", "64.4502", "64.4542",
"64.4571", "64.4806", "64.4812", "64.503", "64.5057", "64.5059",
"64.5492", "64.5666", "64.5669", "64.5809", "64.5871", "64.6244",
"64.6389", "64.7166", "64.7306", "64.73431", "64.75", "64.7507",
"64.7584", "64.7627", "64.8666", "64.9093", "64.9112", "64.9263",
"64.95", "64.96782", "65.0074", "65.0106", "65.0251", "65.0333",
"65.035", "65.0464", "65.062", "65.0706", "65.0942", "65.1049",
"65.1089", "65.1317", "65.1522", "65.1808", "65.23", "65.2365",
"65.2391", "65.25", "65.278", "65.2984", "65.3131", "65.3156",
"65.3235", "65.328", "65.33", "65.3373", "65.4166", "65.5085",
"65.53", "65.5354", "65.5374", "65.5434", "65.5592", "65.5762",
"65.5953", "65.62", "65.6702", "65.6772", "65.68", "65.6935",
"65.6982", "65.7", "65.7166", "65.7306", "65.75272", "65.7666",
"65.7832", "65.7968", "65.8", "65.8077", "65.8151", "65.8211",
"65.8249", "65.8333", "65.8367", "65.85", "65.8769", "65.8801",
"65.8849", "65.8952", "65.9166", "65.9446", "65.9744", "65.9867",
"66.0456", "66.0833", "66.1347", "66.263", "66.2801", "66.2833",
"66.3002", "66.3006", "66.32417", "66.3824", "66.3855", "66.3862",
"66.3888", "66.48", "66.48603", "66.499", "66.50502", "66.5333",
"66.5343", "66.5759", "66.6135", "66.6235", "66.6798", "66.6815",
"66.6932", "66.7265", "66.7374", "66.7529", "66.7586", "66.761",
"66.7666", "66.8107", "66.8542", "66.8876", "66.8888", "67.0919",
"67.1261", "67.1358", "67.1421", "67.1429", "67.1498", "67.1705",
"67.2049", "67.2101", "67.2564", "67.3094", "67.3376", "67.3833",
"67.3956", "67.4083", "67.4964", "67.5009", "67.6501", "67.6943",
"67.7261", "67.7262", "67.7315", "67.7615", "67.827", "67.8488",
"67.85", "67.8911", "67.9113", "67.9443", "68.04398", "68.0502",
"68.0745", "68.2201", "68.2833", "68.3555", "68.3557", "68.4217",
"68.4218", "68.4284", "68.4316", "68.4324", "68.4421", "68.4432",
"68.6777", "68.6779"), class = "factor"), longitude = structure(c(81L,
81L), .Label = c(" longitude", "11", "11.0062", "11.0333", "11.0685",
"11.2", "11.2166", "11.2276", "11.3333", "11.3348", "11.41775",
"11.5332", "11.5572", "11.5724", "11.6015", "11.6077", "11.6352",
"11.6528", "11.7833", "11.8075", "11.8824", "11.9038", "11.9064",
"11.92", "11.9321", "11.9333", "11.9541", "11.97", "11.9746",
"11.9858", "11.9939", "12.038", "12.0387", "12.0542", "12.078",
"12.1009", "12.1032", "12.107", "12.1246", "12.1253", "12.1454",
"12.15406", "12.1563", "12.1581", "12.1761", "12.1833", "12.1997",
"12.1999", "12.2223", "12.2689", "12.2741", "12.2775", "12.2963",
"12.3024", "12.3153", "12.3166", "12.3292", "12.3579", "12.3616",
"12.394", "12.4129", "12.41302", "12.454", "12.4798", "12.5438",
"12.547", "12.55", "12.5514", "12.5521", "12.5843", "12.591",
"12.6043", "12.6381", "12.647", "12.6491", "12.6702", "12.6739",
"12.6775", "12.6906", "12.6928", "12.6959", "12.6969", "12.7",
"12.7042", "12.7074", "12.7075", "12.7166", "12.7264", "12.7653",
"12.77226", "12.7758", "12.8129", "12.8166", "12.819", "12.8203",
"12.8226", "12.8332", "12.8333", "12.8441", "12.8538", "12.8542",
"12.8568", "12.8575", "12.8705", "12.8709", "12.9242", "12.9247",
"12.9333", "12.9359", "12.9414", "12.94361", "12.9493", "12.9834",
"12.9841", "12.9843", "12.9908", "13.0164", "13.0166", "13.0338",
"13.0406", "13.0595", "13.0607", "13.0625", "13.0666", "13.0667",
"13.0668", "13.0731", "13.0734", "13.0746", "13.0817", "13.0833",
"13.1", "13.1109", "13.11383", "13.1166", "13.1174", "13.1193",
"13.1238", "13.1247", "13.1296", "13.1554", "13.1589", "13.16067",
"13.1666", "13.1668", "13.18054263", "13.1865", "13.2152", "13.2166",
"13.229", "13.2318", "13.2369", "13.25", "13.2517", "13.2534",
"13.2593", "13.2666", "13.2833", "13.2841", "13.3157", "13.33",
"13.3374", "13.3508", "13.3563", "13.3608", "13.3787", "13.3826",
"13.3957", "13.3995", "13.4001", "13.4083", "13.4407", "13.4455",
"13.45", "13.4666", "13.4728", "13.4833", "13.5037", "13.5168",
"13.52", "13.5254", "13.5324", "13.5335", "13.5397", "13.55",
"13.5609", "13.6115", "13.6191", "13.6333", "13.6488", "13.6671",
"13.66833", "13.6689", "13.6748", "13.7058", "13.71", "13.7166",
"13.7251", "13.75", "13.7529", "13.78495", "13.7975", "13.7995",
"13.8019", "13.823", "13.8278", "13.8436", "13.8456", "13.85",
"13.87671", "13.88040497", "13.8822", "13.8833", "13.8907", "13.8985",
"13.9333", "13.9432", "13.948", "13.98", "13.986", "14.0375",
"14.0383", "14.0476", "14.0733", "14.0842", "14.0921", "14.1",
"14.1019", "14.10272", "14.1166", "14.1265", "14.1273", "14.1297",
"14.1455", "14.1465", "14.1571", "14.1666", "14.17", "14.1831",
"14.1833", "14.1847", "14.1859", "14.1947", "14.2", "14.2028",
"14.2238", "14.2354", "14.25", "14.2595", "14.2666", "14.2833",
"14.2874", "14.2896", "14.3166", "14.3172", "14.3188", "14.3508",
"14.3578", "14.3678", "14.3692", "14.3786", "14.3903", "14.3951",
"14.4", "14.401", "14.4086", "14.41", "14.4277", "14.4317", "14.4323",
"14.45", "14.451", "14.4666", "14.4672", "14.4693", "14.4863",
"14.4898", "14.507", "14.5085", "14.5126", "14.5535", "14.56389527",
"14.5722", "14.5874", "14.6063", "14.6079", "14.6333", "14.6701",
"14.6786", "14.6895", "14.6931", "14.7", "14.7166", "14.7333",
"14.7342", "14.7571", "14.7908", "14.8015", "14.8024", "14.8176",
"14.826", "14.8324", "14.8488", "14.85", "14.8517", "14.8744",
"14.8833", "14.8881", "14.891", "14.8913", "14.8986", "14.8987",
"14.9", "14.9019", "14.95", "14.9524", "14.9585", "14.97", "14.9853",
"14.986", "14.9943", "14.9948", "15.0146", "15.0167", "15.0206",
"15.03", "15.0455", "15.05", "15.0645", "15.0666", "15.0686",
"15.0854", "15.0876", "15.0929", "15.0984", "15.1045", "15.1145",
"15.12262", "15.1285", "15.1404", "15.1574", "15.164", "15.1694",
"15.2", "15.2184", "15.231", "15.2352", "15.2359", "15.2365",
"15.237", "15.25", "15.2544", "15.2553", "15.2686", "15.2742",
"15.2747", "15.2833", "15.2854", "15.3263", "15.331", "15.3666",
"15.3668", "15.3772", "15.37907", "15.3987", "15.418", "15.4324",
"15.4372", "15.45", "15.4606", "15.4655", "15.47", "15.5", "15.5079",
"15.5192", "15.5327", "15.5331", "15.5333", "15.5423", "15.55",
"15.5555", "15.5561", "15.5725", "15.5857", "15.5894", "15.5921",
"15.6235", "15.6332", "15.6333", "15.6603", "15.6666", "15.67093",
"15.6762", "15.6833", "15.6858", "15.7", "15.7077", "15.7175",
"15.7431", "15.7486", "15.7921", "15.8037", "15.8081", "15.8215",
"15.8232", "15.8245", "15.8307", "15.8333", "15.8352", "15.8518",
"15.8652", "15.9166", "15.9333", "15.9666", "15.9667", "15.9681",
"15.98018143", "15.9833", "15.9883", "15.9909", "16.0017", "16.0353",
"16.0581", "16.0833", "16.1088", "16.1137", "16.1166", "16.1212",
"16.1333", "16.15", "16.15439", "16.1667", "16.1689", "16.1733",
"16.1747", "16.1833", "16.1846", "16.2084", "16.2102", "16.2127",
"16.21345182", "16.2149", "16.2166", "16.2283", "16.2383", "16.2388",
"16.2662", "16.2774", "16.283", "16.2838", "16.2922", "16.2944",
"16.3062", "16.3103", "16.3125", "16.3141", "16.35", "16.3511",
"16.3666", "16.3667", "16.3709", "16.39", "16.3975", "16.401",
"16.4036", "16.4142", "16.4145", "16.4149", "16.41734", "16.4199",
"16.4295", "16.4311", "16.4549", "16.4585", "16.4609", "16.4631",
"16.4647", "16.4648", "16.4683", "16.5333", "16.5358", "16.5393",
"16.5418", "16.55", "16.5505", "16.5536", "16.5682", "16.5812",
"16.5828", "16.5833", "16.6326", "16.6607", "16.6799", "16.68",
"16.6833", "16.6875", "16.6919", "16.7114", "16.7337", "16.7387",
"16.7462", "16.7896", "16.8157", "16.8421", "16.8536", "16.8723",
"16.9166", "16.9168", "16.9531", "16.977", "16.9959", "17.0042",
"17.0095", "17.0106", "17.0262", "17.044", "17.05", "17.0605",
"17.0794", "17.086", "17.0879", "17.09442", "17.0967", "17.0983",
"17.0986", "17.1008", "17.1121", "17.1223", "17.1536", "17.1641",
"17.1693", "17.1748", "17.2", "17.2165", "17.2342", "17.2664",
"17.2802", "17.2854", "17.3188", "17.3333", "17.3409", "17.3447",
"17.3494", "17.3574", "17.40337", "17.4333", "17.4401", "17.441",
"17.4498", "17.4666", "17.4704", "17.4711", "17.4718", "17.5166",
"17.5225", "17.5244", "17.525", "17.5612", "17.5666", "17.5935",
"17.6186", "17.6252", "17.6253", "17.6333", "17.6469", "17.65",
"17.65431", "17.6623", "17.6666", "17.6677", "17.7034", "17.7085",
"17.7166", "17.7426", "17.7478", "17.75", "17.7658", "17.86",
"17.8671", "17.8716", "17.8833", "17.8974", "17.904", "17.9049",
"17.9072", "17.9078", "17.9125", "17.9167", "17.93", "17.9462",
"17.9471", "17.9513", "17.9545", "17.9623", "17.9972", "18.0159",
"18.0179", "18.0234", "18.0575", "18.0577", "18.0592", "18.0618",
"18.0929", "18.1", "18.1166", "18.1184", "18.1302", "18.1471",
"18.1541", "18.1666", "18.1698", "18.1719", "18.1794", "18.2222",
"18.2272", "18.2555", "18.2669", "18.2718", "18.2839", "18.2891",
"18.2943", "18.3061", "18.3308", "18.3428", "18.3656", "18.3725",
"18.3766", "18.3835", "18.3911", "18.419", "18.42533", "18.4333",
"18.4493", "18.4639", "18.5297", "18.5318", "18.55", "18.5502",
"18.5974", "18.6068", "18.6281", "18.6348", "18.6587", "18.6833",
"18.7047", "18.7091", "18.7156", "18.7169", "18.7296", "18.7431",
"18.7436", "18.8146", "18.8206", "18.8211", "18.8417", "18.8666",
"18.9011", "18.9174", "18.9179", "18.9227", "18.9236", "18.9505",
"18.9568", "18.9797", "18.9833", "18.9871", "19.0194", "19.0202",
"19.0233", "19.0532", "19.0611", "19.0929", "19.1298", "19.1592",
"19.1833", "19.197", "19.1975", "19.2", "19.2682", "19.3168",
"19.3782", "19.4087", "19.4746", "19.4833", "19.4875", "19.4976",
"19.5", "19.5058", "19.5059", "19.5666", "19.6314", "19.6673",
"19.67495", "19.6768", "19.6983", "19.6986", "19.7123", "19.7243",
"19.8316", "19.8392", "19.9", "20.02", "20.0993", "20.131", "20.1315",
"20.1543", "20.2124", "20.2333", "20.2397", "20.2747", "20.2901",
"20.2918", "20.3387", "20.3605", "20.4055", "20.424", "20.6333",
"20.6455", "20.6586", "20.6686", "20.7565", "20.7652", "20.7891",
"20.8144", "20.8692", "20.9", "20.9026", "20.9281", "20.9478",
"20.9666", "20.97", "20.9858", "21.0537", "21.0558", "21.0662",
"21.0717", "21.0846", "21.133", "21.15", "21.2263", "21.2666",
"21.27997", "21.3152", "21.4907", "21.52", "21.5274", "21.5277",
"21.55", "21.5655", "21.5666", "21.5787", "21.5791", "21.6098",
"21.6167", "21.6317", "21.6335", "21.6396", "21.75496", "21.76498",
"21.85", "21.9814", "22.109", "22.116", "22.1193", "22.1307",
"22.2178", "22.2334", "22.336", "22.3518", "22.3666", "22.3753",
"22.3961", "22.4488", "22.4502", "22.75", "22.8266", "22.8472",
"22.85", "22.9001", "23.0571", "23.0924", "23.1005", "23.2",
"23.3928", "23.3952", "23.4441", "23.4666", "23.468", "23.622",
"24.113", "24.1162"), class = "factor")), row.names = 1:2, class = "data.frame")
As #IceCreamToucan said, the issue is that your latitude and longitude are factor variables. To fix that, you may use
df$latitude <- as.numeric(as.character(df$latitude))
df$longitude <- as.numeric(as.character(df$longitude))
distHaversine(df[1,], df[2,])
# [1] 0
What's also important is why this happened. In particular, we have
levels(df$latitude)
# [1] " latitude" "55.3376" ...
So, there must be a row with " latitude" as a value in the latitude column. As a result, when loading the data this variable became a factor. Similarly,
levels(df$longitude)
# [1] " longitude" "11" ...
I'll take a wild guess that st is a matrix that includes textual data, therefore all data is coerced as char. try rebuilding your data object as data.frame (which allows multiple data types) and see if problem persists.
> st <- data.frame(name=c("A","B"), latitude = 12.6959, longitude = 60.3097)
> st
name latitude longitude
1 A 12.6959 60.3097
2 B 12.6959 60.3097
> geosphere::distHaversine(st[1,c(3,2)],st[2,c(3,2)])
[1] 0
except for that I agree with everything #julius-vainora has written.
Related
Create a MethylSet class to hold preprocessed data for Illumina methylation microarrays
I want to generate a class met.ms to hold the preprocessed data for an Illumina methylation microarray. I used the getM function, which returns an empty matrix with 0 values. library(minfi) met <- as.matrix(met) met.ms <- getM(MethylSet(Meth = met, Unmeth = met)) dput(met[1:10,1:10]) structure(c(0.461440642939772, 0.143910373119058, 0.847164847154162, 0.737361955793681, 0.716794733144112, 0.351877113536983, 0.248986769373366, 0.0121360989202765, 0.876303885229884, 0.944311384947134, 0.595894468074615, 0.0807243779293262, 0.867305510246114, 0.70680600651273, 0.217862460492399, 0.169408257004071, 0.173115013795265, 0.0108902025634162, 0.813866558997356, 0.938576461648791, 0.481304782143526, 0.437447195378987, 0.898927359292032, 0.758108726247342, 0.868604834806246, 0.577744851436078, 0.567241575633452, 0.0122683781097633, 0.881366097769717, 0.936584647488041, 0.553849599144766, 0.0642332527783939, 0.917290578229414, 0.675537604266578, 0.543087013952312, 0.85044433769089, 0.470810530680518, 0.0125681212511168, 0.870735609192125, 0.956356142020249, 0.184349035247422, 0.126118535539944, 0.928017823091886, 0.677846427070521, 0.850473788130218, 0.44473521937132, 0.204529155293748, 0.0122330126903632, 0.906102120405464, 0.938145301973259, 0.368324568853624, 0.112151024422993, 0.881981171862823, 0.695606438687072, 0.846718372472362, 0.757733166615607, 0.172813874013867, 0.0124341091006015, 0.875702288602203, 0.949350493096875, 0.17338171975844, 0.559088973726113, 0.901815470518336, 0.805920947304252, 0.640825631457383, 0.621308654785173, 0.0722588860930127, 0.0100408106849315, 0.856460615834933, 0.945808996938907, 0.805217631945182, 0.0993225901397478, 0.889537978677822, 0.691597185851671, 0.813122933295151, 0.710712761159508, 0.579117830986195, 0.0145401029579807, 0.833725365229449, 0.930732020027994, 0.113336454896178, 0.0871408483321741, 0.879968490399937, 0.549769911227498, 0.283154379541085, 0.48310833426734, 0.0694935460463862, 0.0126142511240202, 0.885015967416138, 0.933393915741336, 0.451013557269167, 0.0954830889751504, 0.877101253439035, 0.700443114118019, 0.645773476077286, 0.446177255074733, 0.389318735766059, 0.0155373951272166, 0.882984941909313, 0.92890097781832), dim = c(10L, 10L), dimnames = list(c("cg00000029", "cg00000165", "cg00000236", "cg00000289", "cg00000292", "cg00000321", "cg00000363", "cg00000622", "cg00000658", "cg00000721"), c("TCGA-2K-A9WE-01A", "TCGA-2Z-A9J1-01A", "TCGA-2Z-A9J2-01A", "TCGA-2Z-A9J3-01A", "TCGA-2Z-A9J5-01A", "TCGA-2Z-A9J6-01A", "TCGA-2Z-A9J7-01A", "TCGA-2Z-A9J8-01A", "TCGA-2Z-A9J9-01A", "TCGA-2Z-A9JD-01A")))
radius in nn2() function in RANN r-package
I was trying to use the solution offered here to find all the location from df which are within the 70 km distance from my point of interest userLocation=c(6.9,55.2), but it does not work properly ! df = structure(list(lng = c(6.2694184, 6.25737207, 6.23839104, 6.25844252, 6.22595901, 6.21351832, 6.2010845, 6.1886414, 6.1762058, 6.1637609, 6.15132287, 6.13887619, 6.12643637, 6.14361895, 6.16332364, 6.18302157, 6.2027276, 6.22242688, 6.24213488, 6.26842752, 6.26745135, 6.24518597, 6.26645948, 6.24420242, 6.22357831, 6.26548171, 6.24321746, 6.2226023, 6.20041884, 6.18070459, 6.16099845, 6.16716672, 6.17960629, 6.18686265, 6.2078525, 6.19203657, 6.20447434, 6.21691835, 6.2293537, 6.24179593, 6.26009321, 6.26448764, 6.2422317, 6.21927538, 6.20186455, 6.26350828, 6.24124514, 6.22028969, 6.26251321, 6.2402584, 6.23404584, 6.26153227, 6.22171658, 5.94065657, 6.10363006, 6.11606487, 6.12850589, 6.14093826, 6.15337749, 6.16582359, 6.17826103, 6.19070472, 6.20313974, 6.20009703, 5.96044213, 5.96988333, 5.98023582, 5.98966667, 5.99910246, 6.00003829, 6.00947365, 6.01889843, 6.02832882, 6.01983402, 6.02925771, 6.038687, 6.0481219, 6.05754688, 6.03963788, 6.04906608, 6.05848435, 6.06792377, 6.07735326, 6.08677283, 6.05941948, 6.06885218, 6.07829049, 6.08771889, 6.09713671, 6.10657633, 6.11600538, 6.07922538, 6.08864707, 6.10756108, 6.12000483, 6.13243993, 6.12019786, 6.14488189, 6.15733073, 6.16977091, 6.16621949, 6.13805015, 6.13652024, 5.941545, 6.20491484, 6.18423897, 6.17806466, 6.16355552, 6.15738696, 6.14558294, 6.14286638, 6.13670293, 6.12217027, 6.11601258, 6.10148275, 6.09533146, 6.08080511, 6.07464337, 6.06011984, 6.03729438, 6.05394895, 6.02546329, 6.0136389, 6.03674112, 6.05743408, 6.07812006, 6.09879971, 6.11948795, 6.11063647, 6.08914275, 6.08440881, 6.0018212, 6.02491713, 5.98999461, 6.01308427, 5.97815849, 6.00125809, 5.96632973, 5.98943792, 5.9995124, 6.02119838, 6.04364466, 6.0223476, 6.04560587, 6.03821257, 6.06131821, 6.06046748, 5.97888909, 5.95766873, 6.24771247, 6.04931495, 6.25538943, 6.23227728, 6.25434093, 6.25329159, 6.25225759, 6.25120656, 6.25015469, 6.24911757, 6.06338238, 6.08539205, 6.10756976, 6.12975108, 6.15193667, 6.17411029, 6.19630377, 6.21848591, 6.22602495, 6.23123663, 6.20931486, 6.23019515, 6.20826628, 6.22915282, 6.20721685, 6.22810966, 6.21962063, 6.20209266, 6.20618216, 6.19702482, 6.1799057, 6.15772301, 6.13554395, 6.11336914, 6.09118237, 6.09738412, 6.11958004, 6.12698723, 6.14767387, 6.16835417, 6.18613747, 6.185096, 6.165456, 6.14476821, 6.15765091, 6.23561071, 6.08001353, 6.22353732, 6.2376767, 6.21143885, 6.19936347, 6.18727866, 6.17520066, 6.16311385, 6.15103386, 6.13894506, 6.12686243, 6.11478725, 6.10270261, 6.09818625, 6.12128852, 6.2468456, 6.22571713, 6.24558662, 6.22445138, 6.24434288, 6.22320086, 6.24308194, 6.22194875, 6.24182062, 6.22068065, 6.24057332, 6.21942655, 6.2113264, 6.22341814, 6.19699748, 6.18490568, 6.1988361, 6.17283631, 6.16074252, 6.14867115, 6.13657473, 6.13954049, 6.16263694, 6.18482009, 6.20327221, 6.20009595, 6.19278885, 6.17005571 ), lat = c(54.67598304, 54.83924292, 54.83162024, 54.82483795, 54.82033259, 54.80904336, 54.79775292, 54.78646988, 54.77517665, 54.76389082, 54.75260377, 54.74131515, 54.73002531, 54.72096456, 54.71392047, 54.70687309, 54.69983176, 54.69278713, 54.68573957, 54.68934722, 54.7027117, 54.69910571, 54.71606682, 54.71246092, 54.70614626, 54.72943123, 54.72582507, 54.71951053, 54.71576339, 54.72280423, 54.72985112, 54.74274399, 54.75402944, 54.73569581, 54.72983408, 54.7653223, 54.77660496, 54.78789538, 54.79918423, 54.81047187, 54.80230996, 54.74279524, 54.73918917, 54.74155047, 54.75043676, 54.75615956, 54.75255324, 54.75849353, 54.76951451, 54.76590829, 54.77879358, 54.78287875, 54.84106585, 54.79004116, 54.73264696, 54.7439301, 54.755221, 54.76651031, 54.77779842, 54.78908531, 54.80037062, 54.81166369, 54.82295519, 54.83631649, 54.78306731, 54.79535153, 54.77609951, 54.7883729, 54.80065457, 54.76912877, 54.78140068, 54.7936805, 54.80595963, 54.7621547, 54.77443373, 54.78671208, 54.79898973, 54.81126633, 54.75518666, 54.76746422, 54.77974071, 54.7920169, 54.80429202, 54.81656608, 54.74821493, 54.76049101, 54.7727664, 54.78504073, 54.79732298, 54.80959594, 54.82187682, 54.74124062, 54.75351485, 54.76118719, 54.77247897, 54.78376916, 54.79513973, 54.79505815, 54.80634591, 54.8176321, 54.8309898, 54.82587825, 54.81251828, 54.80340625, 54.85043439, 54.85669012, 54.84379843, 54.8629602, 54.85006754, 54.83850747, 54.86921769, 54.85633303, 54.87548056, 54.86259492, 54.88174916, 54.86885358, 54.88800555, 54.8751176, 54.89427628, 54.89688611, 54.88137801, 54.88534048, 54.87379377, 54.87235508, 54.86608859, 54.85982748, 54.85356275, 54.84730376, 54.83491117, 54.82992904, 54.84309445, 54.86224596, 54.86080945, 54.85069668, 54.84926234, 54.8391549, 54.83771415, 54.82760306, 54.82617384, 54.81401612, 54.81866848, 54.82193287, 54.83203, 54.85454492, 54.8418856, 54.84463218, 54.83126946, 54.807705, 54.81314447, 54.95082492, 54.90870481, 54.85261135, 54.8544958, 54.86597391, 54.87933643, 54.89269028, 54.90605271, 54.91941509, 54.93277779, 54.91930405, 54.92337651, 54.92712528, 54.93087901, 54.93462874, 54.93838307, 54.94213376, 54.94588009, 54.93325056, 54.86785843, 54.86365241, 54.88122101, 54.87701472, 54.89458354, 54.890377, 54.90794604, 54.9204011, 54.92916856, 54.90373959, 54.91606989, 54.92541899, 54.92166542, 54.91791682, 54.91416421, 54.91041621, 54.89753741, 54.90128459, 54.88863077, 54.8823668, 54.87609923, 54.88468492, 54.89804726, 54.89094652, 54.89720452, 54.90830415, 55.08370977, 54.93641839, 55.07226944, 55.06170442, 55.06083624, 55.04939327, 55.03795778, 55.02652115, 55.01508302, 55.00364374, 54.99220296, 54.98077001, 54.96932695, 54.95789135, 54.94469353, 54.94333719, 54.96418243, 54.9585686, 54.97754901, 54.9719349, 54.99090692, 54.98529252, 55.00427341, 54.99865908, 55.01763087, 55.01201625, 55.03099761, 55.02538271, 55.03790915, 55.04934232, 55.02208092, 55.01064489, 54.99998971, 54.99920808, 54.98776941, 54.97632995, 54.9648976, 54.95153594, 54.95007267, 54.95382515, 54.96186591, 54.98662348, 54.97394968, 54.97118391)), class = "data.frame", row.names = c(NA, -238L)) What I have done is as follow : Add the point of interest to the beginning of df df = rbind(userLocation,df) Set the radius to 0.64 since according to here, every 0.1 is equivalent to 11.1 km ! radius <- 0.64 #Identifying neighbors res <- nn2(df, k=nrow(df), searchtype="radius", radius = radius) Since my point of interest is the first row in df I would expect all the non zero index in the first row are the points within my 70 km threshold Ind <- res$nn.idx[1,][res$nn.idx[1,]>0] My Ind object has just one value! Ind [1] 1 but if I plot the data, all of the points are within 70 km distance : I would appreciate it if someone could help me here.
Plot VAR fitted values with original data R
Suppose you have a matrix of time series, where each column is a time series. Now, suppose you take second differences of this matrix, (so the data is stationary), using this code: var_train_data <- diff(var_train, differences = 2) and then you estimate this model: var_1 <- VAR(y=var_train_data, lag=9, type="const") Recall that this function VARcomes from vars package. How can you plot the original data and the fitted(var_1) data? Is there a function to return the fitted data from the VAR to "level"? I want to do this but with a VAR. Thanks in advance!! Here is the data: > dput(var_train) structure(c(8.59225428063812, 8.61632381521795, 8.48941975098913, 8.42616336163893, 8.4656261753598, 8.49981580266834, 8.50658473928686, 8.54846279771184, 8.58669260125764, 8.56316032696837, 8.52323490346238, 8.48186742854092, 8.48127581622944, 8.49729119076164, 8.49055049683316, 8.58344453055748, 8.66539149708416, 7.9357662604667, 6.05291235942189, 6.03890804924141, 5.98225560802266, 5.97240914057282, 5.94306180787981, 6.20137810965131, 6.12654161955374, 5.94624694111468, 5.85594359899009, 5.80529348520438, 5.8381279297813, 5.94886540621632, 5.89095336551159, 5.78449385503938, 5.80588769759335, 5.70948049577085, 5.67528501375454, 5.52325929980363, 5.31085745753021, 5.33500450854624, 5.3938341365814, 5.45958551414416, 5.62663959880732, 5.67152161243798, 5.87292229474808, 6.13320939934395, 6.0539450308861, 5.91620206260743, 5.98431404307914, 5.97698522584315, 6.09421451539306, 6.16657264938364, 6.27079937807193, 6.32011405804798, 6.31492735684061, 6.33107810311843, 6.44029387009958, 6.5049295418109, 6.68300329197134, 7.30512711870751, 7.48990882366175, 7.51140038002074, 7.36108949229449, 7.40527167395002, 7.52991897172882, 7.48794703789686, 7.28420343801981, 7.03762657251759, 6.94570770568258, 6.8027650651245, 6.70994292841968, 6.5635196517431, 6.58704241900519, 6.57918807870411, 6.56763428848419, 6.67249919251384, 6.55714884087979, 6.44556863637826, 6.64144323226655, 6.69044694236696, 6.64031146877134, 6.57024614132845, 6.55644009549116, 6.41999492814714, 6.30406385390409, 6.25618617067998, 6.20859002609663, 6.29478035236011, 6.33882450179958, 6.27861522839648, 6.36442286111981, 6.40470239932559, 6.38864543562845, 6.57792182635296, 6.77748387294482, 6.80771392480191, 6.78808230061387, 6.83179944673993, 6.74635337244069, 6.71228769051817, 6.71323231410622, 6.87445699358062, 6.99334898488415, 7.02875008260248, 6.99559171234453, 6.94609768011091, 6.82185333419185, 6.78972221207055, 7.08994524817146, 6.94355669144552, 6.96382050291509, 7.01613754035382, 7.0956860745406, 7.10902496856521, 7.0683268590798, 7.09328003338984, 7.03698767140573, 6.97311732456672, 6.96941465936886, 6.83249279448159, 6.71302370211151, 6.68918458951307, 6.83687286833789, 6.87816384462923, 6.779867793454, 6.6690749885188, 6.68210859744981, 6.63725803128446, 6.47906806746391, 6.63432043737224, 6.57746390143601, 6.63242090143254, 6.51253166492618, 6.61381121689155, 6.59605370068614, 6.52834257739573, 6.38542432810392, 6.40417606373692, 6.39057618124397, 6.38557758480921, 6.40206794670863, 6.38004182339231, 6.33048455580799, 6.31905391015162, 6.18631691346691, 6.16989597138095, 6.18599200958145, 6.15475193126883, 6.10944958256305, 6.07359299021025, 6.30235729839158, 6.21488078851159, 6.19123711209895, 6.13415226194445, 6.10489951928334, 6.10835829857948, 6.17117854049486, 6.20272828827286, 6.14697144970638, 6.11798126273311, 6.09592248164895, 6.04625173074978, 5.99916211737789, 6.01626801829834, 6.07798622087923, 6.06003704039333, 5.96216446139643, 5.8926960131323, 5.91466063648335, 5.87549237085556, 5.89885310338971, 5.9930422492496, 6.02137002988689, 6.01266675475859, 6.15176510875538, 6.27125844671076, 6.34813949104671, 6.50500387674558, 6.50357881390098, 6.4894121494231, 6.48577961874698, 6.65109576407555, 6.55243995455944, 6.52108609966874, 6.61791214295492, 6.73192688164199, 6.82964630649759, 6.7830420348085, 6.67163010253559, 7.35778808496937, 7.68222895818785, 7.65345178297661, 7.75628546245401, 7.62338589734873, 18.0052565534027, 18.0283161481762, 18.0354203734597, 18.071119409619, 18.1057986145642, 18.1434464627582, 18.1679613320011, 18.1724822603554, 18.1626507380013, 18.1735086813587, 18.2048932826437, 18.2692972785199, 18.2533671856288, 18.2415818049433, 18.2496122176447, 18.2718727763864, 18.3010161442641, 18.3291390076371, 18.3572538287519, 18.3507204046193, 18.3600370069532, 18.3939643481435, 18.4165259145903, 18.4908471052973, 18.4867143437776, 18.4804562806922, 18.469238614477, 18.4879629103507, 18.5207111296724, 18.5392075918007, 18.549601058126, 18.5389132074898, 18.5541926126363, 18.5648519425587, 18.6134248798087, 18.6623309458927, 18.6585086859232, 18.6627389755133, 18.6664151651325, 18.7001141293336, 18.7124583930686, 18.7555889295117, 18.7668588119494, 18.7436675451662, 18.7459556596228, 18.7514145615817, 18.7664618044321, 18.8918838160788, 18.8524507901715, 18.8267408416858, 18.8351746759483, 18.8659203733722, 18.8520280137673, 18.8947341990718, 18.8888147953761, 18.8994685106982, 18.9232996525635, 18.8866047503417, 18.9024896904205, 19.0233652386019, 18.987660272875, 18.9544232700339, 18.9334369249929, 18.9449183299094, 18.9631673064947, 18.9933965789268, 18.9872237290741, 18.9873356136058, 19.0123636641398, 19.0206652835947, 19.0270219591515, 19.1598215152463, 19.1409817254047, 19.1376727583276, 19.1107669946426, 19.1241264422661, 19.1370331827589, 19.1912655465102, 19.2115823692113, 19.2158835209359, 19.2414814594526, 19.2701126456528, 19.2843375695361, 19.457274554838, 19.3897327048706, 19.3892248817594, 19.4122218249334, 19.4394604950819, 19.4541631046363, 19.4997359433774, 19.5176831040473, 19.5230181490842, 19.5320146650821, 19.5251016863462, 19.5528663129766, 19.7183358456188, 19.6474484090812, 19.6534432674726, 19.6576920553381, 19.6789279209334, 19.7218625314866, 19.7970056245357, 19.8212720524189, 19.8242227530495, 19.8192388840771, 19.8436023860703, 19.881222941016, 20.0436302759402, 19.9570453168158, 19.9591040082, 19.9740784817898, 19.9751993031549, 19.986022300742, 20.0531114406967, 20.0696985627145, 20.0800828758451, 20.1153963422351, 20.1076549894179, 20.1267044622338, 20.2723835551353, 20.2393724865888, 20.1653637627644, 20.175313365826, 20.1653179028692, 20.2067113730004, 20.2925659543297, 20.2949687148603, 20.3127893925416, 20.3352981379241, 20.3625848609943, 20.4154309157981, 20.5264488163096, 20.4391570088463, 20.4361213999428, 20.4679188013375, 20.4735221776474, 20.5104401429986, 20.5802596472874, 20.5970515415252, 20.6075988336636, 20.6257156522032, 20.6528395142733, 20.7198461324164, 20.7747860368889, 20.739620648921, 20.7095747158136, 20.6824219109357, 20.6683460262695, 20.6916705410586, 20.759196128171, 20.7576642433693, 20.7734082911213, 20.7797650725761, 20.8116082106002, 20.8694893686511, 21.0404672977562, 20.985356981043, 20.9557258620312, 20.9617164802732, 20.9759120662088, 20.9794392421448, 21.0620148226635, 21.0624457124599, 21.0769973151371, 21.0901703250319, 21.098690344787, 21.1226698925968, 21.2711836808076, 21.2200341433781, 21.207193477524, 21.2331394396842, 21.2179204523064, 21.2683699326247, 21.3524515602354, 21.2680244710733, 21.361479141605, 21.3261431820478, 21.26986226303, 21.2991364766223, 21.4762517489448, 21.3298374568077, 21.3331519252179, 21.3667485789704, 21.3885075875912, 21.3906997195313, 21.4381231831175, 21.458826223458, 21.5063778806171, 21.5151033730744, 21.507010374386, 21.5687143378936, 21.7306835559895, 4.44765724836912, 4.47100191330161, 4.54882158610783, 4.5440708847657, 4.51747797566305, 4.55880902228773, 4.58341393701683, 4.64251003043301, 4.67923099142439, 4.67449572095413, 4.61706049834258, 4.66515462150976, 4.68125825810232, 4.66447683681913, 4.67120538921521, 4.75098823360583, 4.7865929014467, 4.76411723853929, 4.80166768795887, 4.80738451939104, 4.72395597727812, 4.70774920353605, 4.73128098441694, 4.7497092825493, 4.70907556418776, 4.76025128174992, 4.78333093429487, 4.83897472963042, 4.84221516595959, 4.84570544645976, 4.86534283142894, 4.83189781246032, 4.88116983304783, 4.93726397688361, 4.9949887298286, 4.99476493720366, 5.03985402500338, 5.08369093771621, 5.14388523087357, 5.18085114132468, 5.24643999990121, 5.29616550395191, 5.31221160299188, 5.19904892834139, 5.11149173059605, 4.91002237688405, 4.74559139066756, 4.62999621355914, 4.65748259587475, 4.62140362369755, 4.62160891785885, 4.64311994758678, 4.72234866533005, 4.80015528005185, 4.76255281172576, 4.81741428916888, 4.78833902844309, 4.84857045098378, 4.88628200385209, 4.90595450753678, 4.94790389478918, 4.92401525818964, 4.95677349014216, 5.01088694769778, 4.9503589208899, 4.92948635242132, 4.93119567690321, 4.95837860539992, 4.97675522372483, 5.02843176452887, 5.06149708771953, 5.11680002731314, 5.15318428207365, 5.18999785496126, 5.22291283107711, 5.27233625060222, 5.23506513572608, 5.22540885753388, 5.23894254044616, 5.2156683767814, 5.20459712839743, 5.16868853558729, 5.18200968431041, 5.1634206717668, 5.17963852108505, 5.21018392350377, 5.23236124392477, 5.21618459500301, 5.15529912255812, 5.08809220037847, 5.1198724394553, 5.14734561157324, 5.15737088983502, 5.14805750597054, 5.13433360782898, 5.13895940081431, 5.16304129678691, 5.17149369912226, 5.1450893326955, 5.12587216446798, 5.11899200918883, 5.10413318074705, 5.1160008826641, 5.13174199954551, 5.1280052744334, 5.11204768607761, 5.10168238434182, 5.12328408372326, 5.11612649122192, 5.14161587137474, 5.13479881416009, 5.14165443688476, 5.12847989418342, 5.13034008951874, 5.11006252539728, 5.07602981399522, 5.04380082747131, 4.9865270245507, 4.93875062722085, 4.83814457466529, 4.73816812891552, 4.76719339629964, 4.73243951213948, 4.7435649612657, 4.77654431271813, 4.75791190194754, 4.69814760133106, 4.63006025665572, 4.62852090719856, 4.62807952037229, 4.56670114439206, 4.50814804330275, 4.44643563505667, 4.47016149299473, 4.53912223957418, 4.57221861050859, 4.61097392628225, 4.63675759989718, 4.63305952571057, 4.63769373351235, 4.63818304039896, 4.66879922486243, 4.65819557081487, 4.71530442638786, 4.75283411765132, 4.75677199897661, 4.70834590013243, 4.70931748325188, 4.68986307689509, 4.66007542691547, 4.68658557879665, 4.71287923105122, 4.74116955758817, 4.75433533727191, 4.79454505679725, 4.80874809318759, 4.86630450704699, 4.84278723259879, 4.83917234051045, 4.85488742314064, 4.89072885950008, 4.88255695031045, 4.86964539401132, 4.85185198871889, 4.88602282140254, 4.89354723701055, 4.80281371512246, 4.75326969467741, 4.7628424628326, 4.77922033722999, 4.78674176423299, 4.81556668261512, 4.79146335227998, 4.74952108237436, 4.77041301487697, 4.71934595594234, 4.74327045521818, 4.7274675891773, 4.76201943815388, 4.78742822435935, 4.7838694829636, 4.70898722458582, 4.54042300123519, 4.43046567457835, 4.51451988598857, 4.60392217055997, 4.635511244447, 4.69067644375465, 4.68405634850711, 4.70605958678574, 4.74618067900467, 4.83260092214898, 4.58877721775886, 4.5853033584615, 4.58186865729406, 4.55644763424071, 4.57312995884514, 4.59141300784382, 4.61405195391224, 4.62539633475001, 4.62855764989542, 4.63775153880854, 4.6400153979937, 4.63484394226681, 4.66244207350167, 4.66434146018009, 4.67076691372282, 4.68407880009055, 4.68958339529632, 4.68622457601331, 4.69208811620889, 4.6940756895394, 4.69428420237835, 4.70035131806994, 4.71249186301022, 4.7271653599702, 4.7349479901132, 4.74160205558268, 4.74031934574645, 4.75062724305051, 4.74555258590119, 4.7562138340694, 4.77117641542375, 4.77731860313779, 4.78678284676528, 4.79153067887926, 4.79406738928742, 4.81477266396795, 4.80529042610458, 4.82344884188224, 4.84012452381554, 4.82978062729767, 4.84653955140898, 4.85661455200409, 4.84934319669535, 4.85983345926684, 4.86432477646786, 4.87752996938969, 4.88896248079701, 4.89778714881147, 4.90781018324614, 4.89428104718603, 4.88909193570591, 4.91223232224708, 4.90441909943736, 4.89184080947695, 4.90838616906774, 4.9120349738912, 4.91193835958192, 4.88849965474606, 4.86952089013496, 4.82754082787148, 4.82297945991404, 4.83636363788566, 4.81537478739995, 4.80170678155239, 4.79837796712813, 4.80808503798778, 4.82809683942688, 4.84168009931907, 4.85375583235012, 4.86250775605786, 4.86576774877652, 4.85101858001533, 4.88095185322792, 4.889979963576, 4.89811535971474, 4.91927159620284, 4.93489213808326, 4.94589827772837, 4.93753721242439, 4.94070114394025, 4.93820671550976, 4.94272951036566, 4.9566005031372, 4.95762163540098, 4.98371534679409, 4.97127518438922, 4.97300329929901, 4.97577277168663, 4.99013444353118, 4.98890830668264, 4.99059253380479, 4.98920233887426, 5.00013814038861, 4.99339203377456, 4.99332756375832, 4.99585549034717, 4.99514277314306, 4.97378016705823, 4.98107090641032, 4.95128483491647, 4.94360774445335, 4.94820569518161, 4.97397566869503, 4.97837258336568, 4.98575124596766, 4.99233525890304, 4.9912972420199, 5.00502716857625, 4.98574031284931, 4.99974886393147, 5.00248006801806, 5.00029210629614, 5.00032426635492, 5.00234130906807, 4.99807143017482, 5.01211153206913, 5.01282969959663, 5.00369558714223, 4.99803646081775, 4.99122145915995, 4.98203245011163, 4.98898183118227, 4.97676031402907, 4.97661306140277, 4.97790228452433, 4.97467881736556, 4.97074319702324, 4.96777121735822, 4.96666260100269, 4.97008836269719, 4.97439822264025, 4.97499263100689, 4.97356254116369, 4.99650332598755, 4.99359641505544, 5.00958842621975, 5.00937803525786, 5.01453325868578, 5.01528247340244, 5.01105287591122, 5.00468878177894, 5.00658901722306, 5.0002693118926, 4.98932483790769, 4.99855492515587, 4.98814720173172, 4.98315862786098, 4.97816073933055, 4.97250227511499, 4.97217034019837, 4.9727134145512, 4.98093640727607, 4.97743699009155, 4.97708205787666, 4.98170032114438, 4.98999371770747, 4.99342868670462, 4.98710032461129, 4.99711328978229, 4.99575482652789, 5.00170349753027, 5.01247168017715, 5.01239395194275, 5.01245423405598, 5.01879001126698, 5.02033652362449, 5.02739033730593, 5.02651459803757, 5.02453819926525, 5.02388052084628, 5.01926462079431, 4.98975208317983, 4.97258722645873, 4.9635436865624, 4.96424225452655, 4.98770778945255, 4.9635436865624, 4.96633503519968, 4.95371214669663, 4.95441761409803, 4.96214508493582, 4.96772779308498, 4.95159275346247, 4.95934199970871, 4.97397130972466, 4.96772779308498, 4.97880057057624, 4.97535347995162, 4.94946885885877, 4.96494033483413, 4.94662996412034, 4.94378298710842, 7.48320429381319, 7.6561645369399, 7.82110610880829, 7.59320189720296, 7.68683478110016, 7.95667983810111, 7.59617632139741, 7.62474227649511, 7.81676325321851, 7.71940521069487, 7.67181853053348, 8.33880996371242, 7.21094058581954, 8.03822762707727, 7.82261070201569, 7.82357158274152, 7.83735667738348, 8.1046367156374, 7.80815635609445, 7.76703032589162, 7.89220083728877, 7.83855143477394, 7.5073939335162, 8.37816256879826, 7.5059752001373, 8.15552853001404, 7.99048020502086, 7.87268970278342, 7.90447413791873, 8.36780891138641, 8.01981945164711, 7.98025535548044, 8.17482965571992, 8.03312420507814, 8.1396225979523, 8.53154436348939, 8.30064119442864, 8.31217764468587, 8.46515718841819, 8.29227902146296, 8.37957956757638, 8.77038284745496, 8.38757448056262, 8.42970131889157, 8.55673020197898, 7.94125019923153, 7.6879198778969, 9.45050056056844, 8.49521672781314, 8.5173342801255, 8.79041321175791, 8.62481679196763, 8.6089805031612, 9.02875849754497, 8.71206191409011, 8.70162108392494, 8.71428574579492, 8.73089101876822, 8.78844251470506, 9.20696012451967, 6.5096550774221, 9.31509857797606, 9.13789797374865, 8.81392733764639, 8.85674985041305, 9.24914586810566, 7.91025892946504, 9.3832351526754, 9.0349150142277, 9.07250596538971, 8.99441603776387, 9.53980564522775, 8.88032246234735, 9.0418287190433, 9.32660204283357, 9.10057585013137, 9.08539025332009, 9.49154546126259, 9.14507434057652, 9.15862717595491, 9.34371391025786, 9.23770140195837, 9.331902300461, 9.84529784537339, 9.22652292064231, 9.36711817060034, 9.45464102264676, 9.43080717829243, 9.48542815127549, 9.80315392429245, 9.46220102483428, 9.49195605787191, 9.58345398545618, 9.63034810064769, 9.62459170291441, 9.97734143922148, 7.7599692507259, 10.24019393111, 9.83720243907435, 9.76324132919314, 9.80448476069629, 10.1429407688952, 9.78954063027604, 9.81148978580127, 9.90999022870695, 9.88337955430856, 9.86638017850479, 10.3500614614058, 8.04569598345531, 10.5137723520267, 10.0317143144973, 10.0016019420988, 10.0649053768744, 10.4518094727319, 10.0925802568863, 10.1154740580661, 10.2417047261218, 10.2102565428829, 9.95096958506337, 10.736142313028, 10.2104846692811, 10.0464027137144, 10.4566501947458, 10.213399969191, 10.4108390826055, 10.7497332163144, 10.3922428157884, 10.3629994803926, 10.5490843518049, 10.5299430900147, 10.5342652815607, 10.903442654213, 10.523826123055, 9.94829558655345, 11.0676534061714, 10.7289541973848, 10.7146558087789, 11.1095150342409, 10.7975434766392, 10.8030323275495, 10.9150557366667, 10.8468764795822, 10.1911966896029, 11.575751749895, 10.8395599835383, 10.9068704738973, 11.155501263489, 11.0291969763111, 11.0962769537602, 11.4469279398172, 11.0612218040278, 11.1062426423224, 11.2517538845846, 11.2333784859651, 10.9841022587667, 11.7991470802475, 11.2598050882812, 11.254649905487, 11.4720292631746, 11.3598860229692, 11.4170427738813, 11.766391720184, 11.4134853828265, 11.4410605118049, 11.5576389232754, 11.5626475736127, 11.5282047555652, 11.9147793383982, 11.4669389639854, 11.5920019692809, 11.7656439584139, 11.5489709584581, 11.6145933534541, 12.0526884789762, 11.5721225093198, 11.5785294086931, 11.9478679038354, 11.7577088515946, 11.644026901156, 12.282699606583, 11.6893399093708, 11.7081194573217, 12.0745898194066, 11.8513909555241, 12.0120697218447, 12.3777829279197, 11.9427908749701, 11.9852440709239, 12.2849763358503, 12.1610242572971, 12.2863478497246, 12.6987948609176, 8.87626014701704, 8.75781187913873, 8.79677757108755, 8.86048921162718, 9.42285091166665, 9.15587149508903, 9.07157541184028, 9.04422296009634, 8.98415367463587, 8.99264229713128, 8.99995926865439, 8.98630888588454, 9.08279027699937, 9.01801415653217, 9.03092644682495, 9.13585333120665, 9.3964555249613, 9.31056129804753, 9.21149824677136, 9.23582853002755, 9.19896921092407, 9.1993094115266, 9.22157244245253, 9.33255711303986, 9.32050974348142, 9.25734511507957, 9.25346237744606, 9.21161756310925, 9.57206242922829, 9.53477519401849, 9.44848135105606, 9.4736925056348, 9.45353618677624, 9.50006144281617, 9.53134203318552, 9.55522920290037, 9.58433205464551, 9.49975115996635, 9.54279990568933, 9.4939629665153, 9.8456088597159, 9.80015328006924, 9.76821638323259, 9.79109456264224, 9.72522763542793, 9.77851709053319, 9.8204171003855, 9.88434452165958, 9.98640258678757, 9.88349657543331, 9.78072105929449, 9.91545274615568, 10.0965440644382, 10.069889220858, 10.1071834236742, 10.0960053864793, 10.0816170924409, 10.0972659507375, 9.98273573064832, 10.0707648293296, 10.0903422031634, 10.0334967498009, 9.988071454218, 10.0452755646408, 10.214325988114, 10.1943936821307, 10.20408926276, 10.1374653682538, 10.1747246925649, 10.1817608649851, 10.1694093867828, 10.2457147073325, 10.2759167729448, 10.2174707468632, 10.2579653028569, 10.3132625062745, 10.5801172770154, 10.5266233798438, 10.5287486381328, 10.4503144592933, 10.481479184849, 10.4934241207427, 10.502542901769, 10.5494285881606, 10.6156346275554, 10.5119074689424, 10.5311093136153, 10.5900727521127, 10.832499150024, 10.7930060469324, 10.775718578877, 10.7531531154054, 10.773311204382, 10.7696395290979, 10.7637570976447, 10.7977938807946, 10.8750990746633, 10.763894326936, 10.7864939948099, 10.8084313558315, 11.0190608163543, 10.9799244653747, 11.0238093735289, 11.0096646409103, 10.9573562063908, 11.0042746906925, 11.0131160377438, 11.0384446615171, 11.0925921149442, 11.016788345678, 11.0067286524726, 11.1218140056974, 11.2613143806394, 11.2211796761646, 11.2935015874788, 11.2367103049134, 11.1817094995799, 11.2157604633905, 11.2061686914688, 11.2392748154291, 11.4109721102435, 11.3043371225574, 11.2735248395737, 11.4375261360429, 11.5623874976603, 11.5247175044255, 11.5814242903823, 11.5093986724378, 11.5000330452891, 11.5579600619228, 11.5311240131655, 11.5954153362326, 11.6738399129326, 11.57644340322, 11.5655204319799, 11.6321174901907, 11.8360148309349, 11.8553639635506, 11.8913520673329, 11.7944527780615, 11.770991474902, 11.8087026529826, 11.7713523360005, 11.884723151518, 11.9993814545919, 11.8115717892501, 11.8332855179777, 11.9237740730483, 12.0455787827743, 12.0702342014546, 12.1012197983564, 12.0183149296719, 12.0336059065465, 12.0269239230024, 12.1132590047525, 12.5264959691571, 12.2615706812812, 12.0565371292502, 12.2657313524817, 12.1439258858968, 12.2359003050756, 12.3309092088311, 12.3771893569204, 12.3071632432092, 12.3196939443778, 12.3000789109455, 12.321469532421, 12.3683550017493, 12.4759510736235, 12.3701719620075, 12.3835321964786, 12.372549767611, 12.5961565138223, 12.6077080727407, 12.5909743980745, 12.5893548765137, 12.5974984744602, 12.6523879936874, 12.6119355657399, 12.6758307918205, 12.8047085707425, 12.7095434517684, 12.7003715885686, 12.7865053255695, 13.0041421782442, 13.0268258741114, 13.0190226032443, 13.0357037893755, 12.9527882182394, 13.0084592868531, 13.0707965999479, 13.1069788399601, 1.04885832686158, 1.06016074629379, 1.0517956106758, 1.02907998600003, 1.05054370620123, 1.07261670636915, 1.0706491823234, 1.0851355199628, 1.08488055975672, 1.08085233559646, 1.081489249884, 1.08587205516048, 1.07249155362154, 1.05497731364761, 1.05675866316574, 1.06428371643968, 1.06065865122313, 1.05621234529568, 1.05339905298902, 1.05787030302435, 1.0658034000068, 1.08707776713932, 1.08626056161822, 1.10238697375394, 1.11390088086972, 1.12120513732074, 1.11937921359653, 1.10341241626668, 1.1156190247407, 1.12376155972358, 1.12411603174635, 1.12183475077377, 1.12994175229071, 1.12956170931204, 1.12199732095331, 1.11645064755987, 1.12481242467782, 1.13066151473637, 1.13028712061827, 1.12694056065497, 1.12382226475179, 1.12352013167586, 1.13391069257413, 1.14763982976838, 1.14481816405703, 1.14852949174863, 1.14182560351963, 1.14086563926171, 1.14491904045717, 1.14897189333479, 1.14616964486707, 1.15074750127031, 1.14681353487065, 1.11151754535415, 1.10497749493861, 1.10963378437214, 1.12415745716768, 1.17507535290893, 1.20285968503846, 1.22784769136553, 1.23940795216891, 1.254741010879, 1.29442450660416, 1.30428779451896, 1.31314618462517, 1.32544236970695, 1.33728107423435, 1.34408499591568, 1.34199331033196, 1.34027541040719, 1.33616830504407, 1.33360421057602, 1.33332422301893, 1.34717794252774, 1.3502492092262, 1.35168291803248, 1.35827816606688, 1.36772644852242, 1.36755741578293, 1.36926148542701, 1.37264481021763, 1.37322962601678, 1.37643913938007, 1.37906284181634, 1.37644362054554, 1.38911039237937, 1.39412557349575, 1.40094895608589, 1.40630864159528, 1.40823485306921, 1.4138446752069, 1.42340582796496, 1.43641264727375, 1.43605231080207, 1.44839810240334, 1.45451041581127, 1.46166006472498, 1.46774816064695, 1.46930608347752, 1.47885183796249, 1.49059366171423, 1.49849145403671, 1.51209667142067, 1.5250141727637, 1.5392257264567, 1.55144303632514, 1.56488453313021, 1.58308777691125, 1.59737589266492, 1.60896279958586, 1.62553339664661, 1.63594174408691, 1.65233080464302, 1.67114336171075, 1.6897476078746, 1.71673790971729, 1.74453973794979, 1.76317526009814, 1.79187692264759, 1.84186982937622, 1.9460629324144, 2.05986108970089, 2.06767436493269, 2.0783176148561, 2.08271855277262, 2.09358626977224, 2.09674958523685, 2.11582742548029, 2.12810020369675, 2.13596929171732, 2.13972610568317, 2.14456803530813, 2.15013985201827, 2.16007349878874, 2.17165498940627, 2.18057666565755, 2.19162746118342, 2.20308765886345, 2.21304799942168, 2.22367586966847, 2.23629862083737, 2.24751866055731, 2.26100586740225, 2.40972893063106, 2.60366275683037, 2.68572993101095, 2.70501080420283, 2.6676315643757, 2.6479269687206, 2.64641010174172, 2.69966594490103, 2.69665303568271, 2.71396750774502, 2.71900427132191, 2.72876269360869, 2.76276620421252, 2.76620189252239, 2.74632816231219, 2.74196673817286, 2.72905831066292, 2.75190757584346, 2.77801573354251, 2.84089580821293, 2.85681823660541, 2.84754572013613, 2.85858396073969, 2.86184353545653, 2.86958309986952, 2.94279115543111, 2.98631808884879, 3.00648449252989, 3.00620698598987, 3.15207693676406, 3.27614511764022, 3.32011714920345, 3.39367422894347, 3.64822360464499, 3.61835354049394, 3.59374251055335, 3.63237359915986, 3.62209957896007, 3.64554153297999, 3.71611226971083, 3.76031231050606, 3.80307769833913, 3.77959145461296, 3.74772344909971, 3.95072671083008, 4.03652777624058, 4.06630193640976, 4.08838169421096, 4.09074775372752), .Dim = c(192L, 7L), .Dimnames = list(NULL, c("EMBI+", "M2 (pesos)", "Commodity Price index", "emae", "gasto programas SS", "recursos tributarios", "ex_rate")), .Tsp = c(2004, 2019.91666666667, 12), class = c("mts", "ts", "matrix"))
Problem with correlog function in pgirness
I am trying to produce an autocorrelogram using output from the correlog function in pgirmess as is described here. My UTM coordinate data are: structure(list(V1 = c(698073L, 698095L, 698274L, 697806L, 698602L, 698632L, 697425L, 698272L, 698125L, 697935L, 698681L, 699287L, 698687L, 698042L, 698052L, 697477L, 698096L, 698782L, 698203L, 698113L, 698046L, 697923L, 699398L, 698143L, 698555L, 697973L, 698042L, 698080L, 697918L, 698253L, 698687L, 698719L, 698079L, 697982L, 698273L, 698995L, 698267L, 700678L, 698087L, 698887L, 698599L, 698883L, 697947L, 698159L, 697464L, 697897L, 698867L, 697775L, 698071L, 698043L, 698115L, 697979L, 697976L, 698064L, 698024L, 698048L, 698200L, 698092L, 698328L, 697998L, 697772L, 697957L, 698590L, 698789L, 698060L, 698071L, 699316L, 699094L, 698633L, 699289L, 698089L, 697819L, 697894L, 698000L, 700218L, 700004L, 699684L, 699743L, 726256L, 724864L, 725175L, 725438L, 725778L, 700386L, 700740L, 700701L, 724204L, 724049L, 723872L, 722994L, 698150L, 698197L, 698064L, 698285L, 698685L, 698716L, 698316L, 698170L, 698920L, 699335L, 698273L, 698100L, 698605L, 698089L, 697784L, 697693L, 697990L, 697809L, 697945L, 698108L, 697945L, 697736L, 698567L, 699035L, 697651L, 698062L, 699035L ), V2 = c(1853363L, 1853581L, 1853596L, 1854098L, 1853795L, 1853764L, 1853338L, 1853684L, 1853627L, 1853540L, 1853912L, 1853399L, 1853897L, 1853236L, 1853744L, 1853505L, 1853458L, 1853926L, 1853736L, 1853858L, 1853783L, 1853586L, 1853612L, 1853498L, 1853834L, 1853269L, 1853528L, 1853639L, 1853533L, 1853503L, 1853897L, 1853704L, 1853685L, 1853638L, 1853595L, 1853602L, 1853530L, 1852898L, 1853424L, 1853770L, 1853792L, 1853859L, 1853586L, 1853708L, 1853603L, 1852869L, 1853973L, 1853898L, 1853608L, 1853762L, 1853695L, 1853586L, 1853617L, 1853775L, 1853251L, 1853162L, 1853693L, 1853603L, 1853654L, 1853463L, 1853532L, 1853392L, 1853853L, 1853843L, 1853550L, 1853587L, 1853509L, 1853461L, 1853724L, 1853506L, 1853535L, 1853643L, 1853807L, 1853556L, 1852417L, 1852815L, 1853113L, 1852880L, 1785260L, 1786479L, 1786054L, 1785839L, 1785467L, 1852514L, 1852029L, 1852391L, 1787745L, 1787746L, 1787926L, 1788326L, 1853416L, 1853437L, 1853409L, 1853531L, 1853848L, 1853734L, 1853660L, 1853465L, 1854071L, 1853365L, 1853577L, 1853698L, 1853878L, 1853286L, 1853532L, 1853503L, 1853423L, 1854024L, 1854096L, 1853483L, 1853798L, 1853664L, 1853804L, 1852806L, 1853503L, 1853304L, 1852806L)), class = "data.frame", row.names = c(NA, -117L)) My response variable data are: c(44.172, 43.975, 43.338, 43.854, 41.475, 42.414, 45.035, 44.025, 43.278, 44.116, 44.606, 44.242, 45.682, 44.495, 42.732, 44.02, 44.626, 43.535, 44.025, 43.409, 43.207, 43.46, 42.505, 45.348, 42.495, 44.505, 43.636, 42.879, 42.086, 43.364, 43.667, 43.005, 43.939, 44.813, 45.364, 42.475, 43.768, 42.909, 43.535, 44.949, 43.187, 42.5, 43.495, 43.318, 42.561, 43.747, 42.005, 44.293, 44.808, 43.702, 42.677, 44.566, 45.237, 43.859, 44.237, 43.909, 44.596, 44.667, 44.04, 44, 42.192, 44.929, 42.949, 43.944, 43.53, 43.298, 43.025, 43.424, 43.712, 42.51, 44.152, 44.01, 41.833, 43.505, 44.646, 44.566, 42.929, 43.636, 44.54, 43.232, 43.182, 42.217, 43.904, 42.864, 43.475, 42.323, 43.025, 43.429, 43.298, 44.914, 42.884, 43.601, 44.475, 42.505, 41.268, 44.227, 42.955, 42.833, 46.056, 44.293, 42.556, 43.717, 43.283, 43.086, 42.707, 43.859, 42.884, 44.682, 41.551, 42.803, 45.242, 42.929, 42.848, 44.288, 43.283, 43.288, 44.444) I tried: pgi.cor <- correlog(coords=coords, z=sp.rich$mean], method="Moran",nbclass=11), but this appears to have cause problem calculating distances between the duplicate coordinates: Error in dnearneigh(coords[-zero, ], breaks[i, 1], breaks[i, 2]) : non-positive number of rows in x Therefore, I tried: pgi.cor <- correlog(coords=unique(coords), z=sp.rich$mean[-c(31,117)], method="Moran",nbclass=11) (because rows 31 and 117 are duplicates of other rows). However this gives me the same error result. Any ideas? Thanks!
Getting date to appear on x axis of plot.stl method in R
I was wondering if anyone knows of a way to get the dates to appear on the x axis of an stl plot. res<- (stl(ts(data[,variable],frequency=52,start=as.Date(data[1,date]) ),s.window="per",robust=TRUE) ) plot(res) However this is just producing some unicode labels at the bottom of the chart, I have also tried chaning as.Date to as.character however this didn't work. dput of some data: structure(c("2007-01-01", "2007-01-08", "2007-01-15", "2007-01-22", "2007-01-29", "2007-02-05", "2007-02-12", "2007-02-19", "2007-02-26", "2007-03-05", "2007-03-12", "2007-03-19", "2007-03-26", "2007-04-02", "2007-04-09", "2007-04-16", "2007-04-23", "2007-04-30", "2007-05-07", "2007-05-14", "2007-05-21", "2007-05-28", "2007-06-04", "2007-06-11", "2007-06-18", "2007-06-25", "2007-07-02", "2007-07-09", "2007-07-16", "2007-07-23", "2007-07-30", "2007-08-06", "2007-08-13", "2007-08-20", "2007-08-27", "2007-09-03", "2007-09-10", "2007-09-17", "2007-09-24", "2007-10-01", "2007-10-08", "2007-10-15", "2007-10-22", "2007-10-29", "2007-11-05", "2007-11-12", "2007-11-19", "2007-11-26", "2007-12-03", "2007-12-10", "2007-12-17", "2007-12-24", "2007-12-31", "2008-01-07", "2008-01-14", "2008-01-21", "2008-01-28", "2008-02-04", "2008-02-11", "2008-02-18", "2008-02-25", "2008-03-03", "2008-03-10", "2008-03-17", "2008-03-24", "2008-03-31", "2008-04-07", "2008-04-14", "2008-04-21", "2008-04-28", "2008-05-05", "2008-05-12", "2008-05-19", "2008-05-26", "2008-06-02", "2008-06-09", "2008-06-16", "2008-06-23", "2008-06-30", "2008-07-07", "2008-07-14", "2008-07-21", "2008-07-28", "2008-08-04", "2008-08-11", "2008-08-18", "2008-08-25", "2008-09-01", "2008-09-08", "2008-09-15", "2008-09-22", "2008-09-29", "2008-10-06", "2008-10-13", "2008-10-20", "2008-10-27", "2008-11-03", "2008-11-10", "2008-11-17", "2008-11-24", "2008-12-01", "2008-12-08", "2008-12-15", "2008-12-22", "2008-12-29", "2009-01-05", "2009-01-12", "2009-01-19", "2009-01-26", "2009-02-02", "2009-02-09", "2009-02-16", "2009-02-23", "2009-03-02", "2009-03-09", "2009-03-16", "2009-03-23", "2009-03-30", "2009-04-06", "2009-04-13", "2009-04-20", "2009-04-27", "2009-05-04", "2009-05-11", "2009-05-18", "2009-05-25", "2009-06-01", "2009-06-08", "2009-06-15", "2009-06-22", "2009-06-29", "2009-07-06", "2009-07-13", "2009-07-20", "2009-07-27", "2009-08-03", "2009-08-10", "2009-08-17", "2009-08-24", "2009-08-31", "2009-09-07", "2009-09-14", "2009-09-21", "2009-09-28", "2009-10-05", "2009-10-12", "2009-10-19", "2009-10-26", "2009-11-02", "2009-11-09", "2009-11-16", "2009-11-23", "2009-11-30", "2009-12-07", "2009-12-14", "2009-12-21", "2009-12-28", "2010-01-04", "2010-01-11", "2010-01-18", "2010-01-25", "2010-02-01", "2010-02-08", "2010-02-15", "2010-02-22", "2010-03-01", "2010-03-08", "2010-03-15", "2010-03-22", "2010-03-29", "2010-04-05", "2010-04-12", "2010-04-19", "2010-04-26", "2010-05-03", "2010-05-10", "2010-05-17", "2010-05-24", "2010-05-31", "2010-06-07", "2010-06-14", "2010-06-21", "2010-06-28", "2010-07-05", "2010-07-12", "2010-07-19", "2010-07-26", "2010-08-02", "2010-08-09", "2010-08-16", "2010-08-23", "2010-08-30", "2010-09-06", "2010-09-13", "2010-09-20", "2010-09-27", "2010-10-04", "2010-10-11", "2010-10-18", "2010-10-25", "2010-11-01", "2010-11-08", "2010-11-15", "2010-11-22", "2010-11-29", "2010-12-06", "2010-12-13", "2010-12-20", "2010-12-27", "2011-01-03", "2011-01-10", "2011-01-17", "2011-01-24", "2011-01-31", "2011-02-07", "2011-02-14", "2011-02-21", "2011-02-28", "2011-03-07", "2011-03-14", "2011-03-21", "2011-03-28", "2011-04-04", "2011-04-11", "2011-04-18", "2011-04-25", "2011-05-02", "2011-05-09", "2011-05-16", "2011-05-23", "2011-05-30", "2011-06-06", "2011-06-13", "2011-06-20", "2011-06-27", "2011-07-04", "2011-07-11", "2011-07-18", "2011-07-25", "2011-08-01", "2011-08-08", "2011-08-15", "2011-08-22", "2011-08-29", "2011-09-05", "2011-09-12", "2011-09-19", "2011-09-26", "2011-10-03", "2011-10-10", "2011-10-17", "2011-10-24", "2011-10-31", "2011-11-07", "2011-11-14", "2011-11-21", "2011-11-28", "2011-12-05", "2011-12-12", "2011-12-19", "2011-12-26", "442573", "452832", "452785", "459228", "479509", "477631", "465619", "462001", "485567", "462381", "456059", "457401", "474094", "468766", "456945", "539126", "545640", "511801", "486619", "484430", "481428", "470622", "479677", "486755", "477617", "483656", "497479", "493436", "480080", "481527", "516029", "532349", "503939", "472171", "461550", "504532", "489715", "480032", "488376", "470772", "467395", "488155", "455712", "474456", "471237", "482943", "459320", "456956", "465056", "461930", "441201", "451255", "464508", "449199", "455411", "476323", "521761", "513416", "521070", "497596", "485461", "485593", "461148", "429938", "441207", "459484", "462099", "469285", "454395", "456729", "469251", "517727", "526719", "477985", "484538", "469766", "472399", "481162", "479039", "481071", "485068", "462108", "459079", "452410", "488574", "502166", "504323", "514529", "524206", "504315", "462935", "461899", "461551", "455491", "456857", "443314", "454586", "458943", "450555", "454311", "442808", "440126", "414876", "415787", "413352", "423864", "448319", "415440", "431948", "433313", "448509", "436400", "454154", "454183", "447735", "452220", "451433", "472808", "446767", "426595", "463693", "435673", "452704", "456828", "465069", "448685", "457353", "443859", "463972", "480139", "493342", "500982", "529602", "527365", "512005", "484585", "455007", "470006", "477522", "443956", "459038", "488877", "466669", "476242", "470862", "457298", "466438", "454062", "460216", "466645", "445113", "457255", "451553", "451504", "447991", "435100", "416140", "481390", "489041", "496984", "486245", "478191", "455201", "448085", "459097", "480859", "490248", "462523", "489755", "468391", "460229", "481276", "472845", "481099", "476435", "487314", "475043", "476847", "461928", "483488", "479379", "456732", "461538", "480773", "471101", "459898", "482129", "464356", "459420", "457850", "456764", "438152", "467928", "464732", "458767", "470256", "449488", "433263", "428548", "435099", "429163", "424251", "434723", "425841", "399498", "418791", "405051", "385037", "425144", "418296", "397644", "414283", "431907", "429117", "424862", "439664", "432791", "443588", "434985", "442418", "445760", "449290", "451412", "456247", "444372", "441390", "458192", "456435", "450670", "447609", "439083", "464513", "462784", "439423", "450857", "442374", "447753", "440207", "435254", "430841", "437233", "426523", "430127", "431305", "470244", "508878", "511064", "504182", "462076", "452218", "426535", "436892", "459008", "441449", "438783", "427497", "432275", "436745", "423068", "429574", "416074"), .Dim = c(261L, 2L))
The problem is with how you have created the time series object. ?ts will give you start : the time of the first observation. Either a single number or a vector of two integers, which specify a natural time unit and a (1-based) number of samples into the time unit. Since your data starts at 2007-01-01 and is a weekly data, you have to specify c(2007,1), Note that the "1" here denotes that data start from the 1st week of 2007, as the data is weekly. Here the frequency should be set to 52 because, after 52 cycles/weeks a year will change from 2007 to 2008. This should work res<- (stl(ts(data[,2],frequency=52,start=c(2007,1 )),s.window="per",robust=TRUE) )