How can I convert this extense laTeX written equation to a C++ code? [closed] - math

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 days ago.
Improve this question
This is the code that I want to convert to C++ code for an Arduino Mega. Please any ideas?
-\frac{c x \cos (r) \cos \left(\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right)}{\sqrt{x^2-2 a \cos (r) x+2 c \sin (r) x+y^2+a^2 \cos ^2(r)+c^2 \cos ^2(r)+a^2 \sin ^2(r)+c^2 \sin ^2(r)-2 c y \cos (r)-2 a y \sin (r)}}+\frac{a y \cos (r) \cos \left(\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right)}{\sqrt{x^2-2 a \cos (r) x+2 c \sin (r) x+y^2+a^2 \cos ^2(r)+c^2 \cos ^2(r)+a^2 \sin ^2(r)+c^2 \sin ^2(r)-2 c y \cos (r)-2 a y \sin (r)}}-\frac{a x \cos \left(\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \sin (r)}{\sqrt{x^2-2 a \cos (r) x+2 c \sin (r) x+y^2+a^2 \cos ^2(r)+c^2 \cos ^2(r)+a^2 \sin ^2(r)+c^2 \sin ^2(r)-2 c y \cos (r)-2 a y \sin (r)}}-\frac{c y \cos \left(\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \sin (r)}{\sqrt{x^2-2 a \cos (r) x+2 c \sin (r) x+y^2+a^2 \cos ^2(r)+c^2 \cos ^2(r)+a^2 \sin ^2(r)+c^2 \sin ^2(r)-2 c y \cos (r)-2 a y \sin (r)}}+\frac{c d \cos (r) \cos \left(\tan ^{-1}(0,x-a \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right)}{\sqrt{d^2-2 x d-2 b \cos (r) d-2 c \sin (r) d+x^2+y^2+b^2 \cos ^2(r)+c^2 \cos ^2(r)+b^2 \sin ^2(r)+c^2 \sin ^2(r)+2 b x \cos (r)-2 c y \cos (r)+2 c x \sin (r)+2 b y \sin (r)}}-\frac{c x \cos (r) \cos \left(\tan ^{-1}(0,x-a \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right)}{\sqrt{d^2-2 x d-2 b \cos (r) d-2 c \sin (r) d+x^2+y^2+b^2 \cos ^2(r)+c^2 \cos ^2(r)+b^2 \sin ^2(r)+c^2 \sin ^2(r)+2 b x \cos (r)-2 c y \cos (r)+2 c x \sin (r)+2 b y \sin (r)}}-\frac{b y \cos (r) \cos \left(\tan ^{-1}(0,x-a \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right)}{\sqrt{d^2-2 x d-2 b \cos (r) d-2 c \sin (r) d+x^2+y^2+b^2 \cos ^2(r)+c^2 \cos ^2(r)+b^2 \sin ^2(r)+c^2 \sin ^2(r)+2 b x \cos (r)-2 c y \cos (r)+2 c x \sin (r)+2 b y \sin (r)}}-\frac{b d \cos \left(\tan ^{-1}(0,x-a \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \sin (r)}{\sqrt{d^2-2 x d-2 b \cos (r) d-2 c \sin (r) d+x^2+y^2+b^2 \cos ^2(r)+c^2 \cos ^2(r)+b^2 \sin ^2(r)+c^2 \sin ^2(r)+2 b x \cos (r)-2 c y \cos (r)+2 c x \sin (r)+2 b y \sin (r)}}+\frac{b x \cos \left(\tan ^{-1}(0,x-a \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \sin (r)}{\sqrt{d^2-2 x d-2 b \cos (r) d-2 c \sin (r) d+x^2+y^2+b^2 \cos ^2(r)+c^2 \cos ^2(r)+b^2 \sin ^2(r)+c^2 \sin ^2(r)+2 b x \cos (r)-2 c y \cos (r)+2 c x \sin (r)+2 b y \sin (r)}}-\frac{c y \cos \left(\tan ^{-1}(0,x-a \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \csc \left(-\tan ^{-1}(0,-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(0,x-a \cos (r)+c \sin (r))-\tan ^{-1}(y-c \cos (r)+b \sin (r),-d+x+b \cos (r)+c \sin (r))+\tan ^{-1}(y-c \cos (r)-a \sin (r),x-a \cos (r)+c \sin (r))\right) \sin (r)}{\sqrt{d^2-2 x d-2 b \cos (r) d-2 c \sin (r) d+x^2+y^2+b^2 \cos ^2(r)+c^2 \cos ^2(r)+b^2 \sin ^2(r)+c^2 \sin ^2(r)+2 b x \cos (r)-2 c y \cos (r)+2 c x \sin (r)+2 b y \sin (r)}}
This code has been obtained with Wolfram Mathematica, I tried to convert it to code with emacs, but I don't know what I did bad?
This was the method I tried Link

Related

Predicted values for conditional logistic regression greater than 1

I have a multivariate conditional logistic regression model. Case and controls are matched on a 1 to many basis.
I want to make predictions using the model. However, the predicted values I keep getting are between 0 and 3 when they should be binary (0 or 1). Why don't I get binary values?
This is my data:
survival1 is binary.
IC is also binary.
Test_intensity-cat is categorical with 4 levels.
Herd_size_cat is also categorical with 4 levels.
Group has groups in the original data set. I've just included 11 here. The subset of data doesn't converge but the original set does.
n survival1 IC test_intensity_cat herd_size_cat group
1 0 none 1.2 < test/yr <= 1.5 medium 628
2 0 none <= 1.2 test/yr medium 629
3 0 none >= 2 tests/yr very large 627
4 1 IC >= 2 tests/yr very large 628
5 0 none <= 1.2 test/yr large 627
6 1 IC >= 2 tests/yr very large 627
7 1 none >= 2 tests/yr very large 627
8 0 none 1.5 < test/yr <= 2 large 629
9 0 IC 1.5 < test/yr <= 2 very large 629
10 0 none 1.5 < test/yr <= 2 large 628
11 0 none <= 1.2 test/yr large 628
12 0 none 1.5 < test/yr <= 2 small 231
13 0 none 1.5 < test/yr <= 2 very large 231
14 0 none 1.2 < test/yr <= 1.5 very large 231
15 0 IC 1.5 < test/yr <= 2 very large 231
16 1 none >= 2 tests/yr very large 170
17 0 none 1.2 < test/yr <= 1.5 very large 170
18 0 none >= 2 tests/yr very large 170
19 1 none >= 2 tests/yr medium 582
20 0 none 1.5 < test/yr <= 2 small 583
21 0 IC 1.5 < test/yr <= 2 large 582
22 1 none >= 2 tests/yr large 583
23 0 none 1.2 < test/yr <= 1.5 very large 134
24 0 none 1.2 < test/yr <= 1.5 very large 134
25 0 none <= 1.2 test/yr small 134
26 0 IC 1.5 < test/yr <= 2 very large 134
27 0 none 1.2 < test/yr <= 1.5 very large 484
28 0 none >= 2 tests/yr very large 485
29 0 IC 1.5 < test/yr <= 2 medium 484
30 0 none 1.5 < test/yr <= 2 large 485
31 0 none 1.5 < test/yr <= 2 small 484
32 0 IC <= 1.2 test/yr very large 485
33 0 none 1.2 < test/yr <= 1.5 very large 484
34 0 none 1.5 < test/yr <= 2 very large 485
35 0 none <= 1.2 test/yr medium 76
36 0 none >= 2 tests/yr very large 76
37 0 none >= 2 tests/yr large 76
38 0 IC >= 2 tests/yr medium 76
39 0 none <= 1.2 test/yr very large 629
40 0 none 1.5 < test/yr <= 2 medium 582
41 0 IC >= 2 tests/yr large 170
42 1 IC 1.2 < test/yr <= 1.5 small 583
43 0 none 1.5 < test/yr <= 2 small 582
44 0 none <= 1.2 test/yr small 583
This is my code is in R studio:
library(tidyverse)
library(broom)
library(survival)
model_IC_intensity_size <-
clogit(survival1 ~ IC + test_intensity_cat + herd_size_cat + strata(group),
method = "exact",
data = LCT_herd_matched)
actual <- LCT_herd_matched$survival1
predicted <- round(predict(model_IC_intensity_size, type = "expected"))
table(predicted, actual)
This is the output with the original dataset. The subset gives a smaller version that includes an aberrant 2.
actual
predicted 0 1
0 9271 641
1 185 434
2 6 42
3 0 2
I'm also want to calculate leverage, delta chi squared and the delta beta statistics (p 425 Veterinary Epidemiologic Research by Dohoo et al). How would I go about determining these diagnostics for a conditional logistic regression model in R?
dput(mini)
structure(list(survival1 = c(0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0), IC = structure(c(1L, 1L,
1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L), .Label = c("none", "IC"
), class = "factor"), test_intensity_cat = structure(c(3L, 1L,
2L, 2L, 1L, 2L, 2L, 4L, 4L, 4L, 1L, 4L, 4L, 3L, 4L, 2L, 3L, 2L,
2L, 4L, 4L, 2L, 3L, 3L, 1L, 4L, 3L, 2L, 4L, 4L, 4L, 1L, 3L, 4L,
1L, 2L, 2L, 2L, 1L, 4L, 2L, 3L, 4L, 1L), .Label = c("<= 1.2 test/yr",
">= 2 tests/yr", "1.2 < test/yr <= 1.5", "1.5 < test/yr <= 2"
), class = "factor"), herd_size_cat = structure(c(2L, 2L, 4L,
4L, 3L, 4L, 4L, 3L, 4L, 3L, 3L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 2L,
1L, 3L, 3L, 4L, 4L, 1L, 4L, 4L, 4L, 2L, 3L, 1L, 4L, 4L, 4L, 2L,
4L, 3L, 2L, 4L, 2L, 3L, 1L, 1L, 1L), .Label = c("small", "medium",
"large", "very large"), class = "factor"), group = structure(c(627L,
628L, 626L, 627L, 626L, 626L, 626L, 628L, 628L, 627L, 627L, 231L,
231L, 231L, 231L, 170L, 170L, 170L, 581L, 582L, 581L, 582L, 134L,
134L, 134L, 134L, 483L, 484L, 483L, 484L, 483L, 484L, 483L, 484L,
76L, 76L, 76L, 76L, 628L, 581L, 170L, 582L, 581L, 582L), .Label =
c("1",
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13",
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
"36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46",
"47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57",
"58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68",
"69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
"91", "92", "93", "94", "95", "96", "97", "98", "99", "100",
"101", "102", "103", "104", "105", "106", "107", "108", "109",
"110", "111", "112", "113", "114", "115", "116", "117", "118",
"119", "120", "121", "122", "123", "124", "125", "126", "127",
"128", "129", "130", "131", "132", "133", "134", "135", "136",
"137", "138", "139", "140", "141", "142", "143", "144", "145",
"146", "147", "148", "149", "150", "151", "152", "153", "154",
"155", "156", "157", "158", "159", "160", "161", "162", "163",
"164", "165", "166", "167", "168", "169", "170", "171", "172",
"173", "174", "175", "176", "177", "178", "179", "180", "181",
"182", "183", "184", "185", "186", "187", "188", "189", "190",
"191", "192", "193", "194", "195", "196", "197", "198", "199",
"200", "201", "202", "203", "204", "205", "206", "207", "208",
"209", "210", "211", "212", "213", "214", "215", "216", "217",
"218", "219", "220", "221", "222", "223", "224", "225", "226",
"227", "228", "229", "230", "231", "232", "233", "234", "235",
"236", "237", "238", "239", "240", "241", "242", "243", "244",
"245", "246", "247", "248", "249", "250", "251", "252", "253",
"254", "255", "256", "257", "258", "259", "260", "261", "262",
"263", "264", "265", "266", "267", "268", "269", "270", "271",
"272", "273", "274", "275", "276", "277", "278", "280", "281",
"282", "283", "284", "285", "286", "287", "288", "289", "290",
"291", "292", "293", "294", "295", "296", "297", "298", "299",
"300", "301", "302", "303", "304", "305", "306", "307", "308",
"309", "310", "311", "312", "313", "314", "315", "316", "317",
"318", "319", "320", "321", "322", "323", "324", "325", "326",
"327", "328", "329", "330", "331", "332", "333", "334", "335",
"336", "337", "338", "339", "340", "341", "342", "343", "344",
"345", "346", "347", "348", "349", "350", "351", "352", "353",
"354", "355", "356", "357", "358", "359", "360", "361", "362",
"363", "364", "365", "366", "367", "368", "369", "370", "371",
"372", "373", "374", "375", "376", "377", "378", "379", "380",
"381", "382", "383", "384", "385", "386", "387", "388", "389",
"390", "391", "392", "393", "394", "395", "396", "397", "398",
"399", "400", "401", "402", "403", "404", "405", "406", "407",
"408", "409", "410", "411", "412", "413", "414", "415", "416",
"417", "418", "419", "420", "421", "422", "423", "424", "425",
"426", "427", "428", "429", "430", "431", "432", "433", "434",
"435", "436", "437", "438", "439", "440", "441", "442", "443",
"444", "445", "446", "447", "448", "449", "450", "451", "452",
"453", "454", "455", "456", "457", "458", "459", "460", "461",
"462", "463", "464", "465", "466", "467", "468", "469", "470",
"471", "472", "473", "474", "475", "476", "477", "478", "479",
"480", "481", "482", "483", "484", "485", "486", "487", "488",
"489", "490", "491", "492", "493", "494", "495", "496", "497",
"498", "499", "500", "501", "502", "503", "504", "505", "506",
"507", "508", "509", "510", "511", "512", "513", "514", "515",
"516", "517", "518", "519", "520", "521", "522", "523", "524",
"525", "526", "527", "528", "529", "530", "531", "532", "533",
"534", "535", "536", "537", "538", "539", "540", "541", "542",
"543", "544", "545", "546", "547", "548", "549", "550", "551",
"552", "553", "554", "555", "556", "557", "558", "559", "560",
"561", "562", "563", "564", "565", "566", "567", "568", "569",
"570", "571", "572", "573", "574", "575", "576", "577", "578",
"579", "580", "581", "582", "583", "584", "585", "586", "587",
"588", "589", "590", "591", "592", "593", "594", "595", "596",
"597", "598", "599", "600", "601", "602", "603", "604", "605",
"606", "607", "608", "609", "610", "611", "612", "613", "614",
"615", "616", "617", "618", "619", "620", "621", "622", "623",
"624", "625", "626", "627", "628", "629", "630", "631", "632",
"633", "635", "636", "637", "638", "639", "640", "641", "642",
"643", "644", "645", "646", "647", "648", "649", "650", "651",
"652", "653", "654", "655", "656", "657", "658", "659", "660",
"661", "662", "663", "664", "665", "666", "667", "668", "669",
"670", "671", "672", "673", "674", "675", "676", "677", "678",
"679", "680", "681", "682", "683", "684", "685", "686", "687",
"688", "689", "690", "691", "692", "693", "694", "695", "696",
"697", "698", "699", "700", "701", "702", "703", "704", "705",
"706", "707", "708", "709", "710", "711", "712", "713", "714",
"715", "716", "717", "718", "719", "720", "721", "722", "723",
"724", "725", "726", "727", "728", "729", "730", "731", "732",
"733", "734", "745", "746", "747", "748", "749", "750", "751",
"752", "753", "754", "755", "756", "757", "758", "759", "760",
"761", "762", "763", "764", "765", "766", "767", "986", "987"
), class = "factor")), row.names = c(NA, -44L), class = "data.frame")
I work in a different field but encountered similar issues when making predictions from clogit models. It appears there's different schools of thought on whether making predictions is even valid from these models (see comments in this thread How to get fitted values from clogit model). Nevertheless, we attempted Terry Therneu's workaround presented in the above link. Although I can't reproduce you're data, below is a hypothetical and generic example of what we did. Essentially, we averaged predictions across strata. Would be interested in commentary from experts of which I am not one.
library(tidyverse)
library(ggplot2)
library(survival)
dat <- data.frame(event = c(0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),
strata = factor(c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5)),
cont_var1 = c(100, 90, 10, 20, 60, 95, 85, 15, 25, 65, 90, 80,
20, 30, 70, 100, 90, 10, 20, 60, 90, 80, 20, 30, 70),
cat_var = factor(c("a","a","a","a","a","a","a","a","a","a","b","b","b","b",
"b","b","b","b","b","b","a","a","a","a","a")))
m1 <- clogit(event ~ cont_var1 + cat_var + strata(strata), data = dat, iter.max = 100)
# new dataframe
newdat <- expand_grid(cont_var1 = seq(20, 100, 1),
cat_var = factor(c("a"),
levels = c("a", "b")),
strata = strata(unique(dat$strata)))
# predict
pred_dat <- newdat %>%
bind_cols(predict(m1,
newdata = newdat,
type = "risk",
se.fit = TRUE))
# plot (note first step calculating probability from predictions)
pred_dat %>%
mutate(prob = fit / (1 + fit),
low = (fit - 1.96 * se.fit) / (1 + (fit - 1.96 * se.fit)),
up = (fit + 1.96 * se.fit) / (1 + (fit + 1.96 * se.fit)),
low = ifelse(low < 0, 0, low),
up = ifelse(up > 1, 1, up)) %>%
group_by(cont_var1) %>%
summarise(prob = mean(prob), low = mean(low), up = mean(up)) %>%
ggplot()+
geom_line(aes(x = cont_var1, y = prob)) +
geom_ribbon(aes(x = cont_var1, y = prob, ymin = low, ymax = up), alpha = 0.1) +
theme_classic(base_size = 16) +
labs(y = "Probability (level 'a')", x = "Continuous Variable")

Counting observations per month in a data frame

I currently have a dataframe that has two columns: arrest date and number of arrests. The date column has almost every single day from 2006-2020; instead of having the number of arrests per day, I'd like to have the number of arrests per month, per year.
The dataframe is going to be converted into an xts object for a time series analysis so I need a resulting date column that has the year and month.
Below is the first 6 months of data from the dataset:
structure(list(ARREST_DATE = structure(c(13149, 13150, 13151,
13152, 13153, 13154, 13155, 13156, 13157, 13158, 13159, 13160,
13161, 13162, 13163, 13164, 13165, 13166, 13167, 13168, 13169,
13170, 13171, 13172, 13173, 13174, 13175, 13176, 13177, 13178,
13179, 13180, 13181, 13182, 13183, 13184, 13185, 13186, 13187,
13188, 13189, 13190, 13191, 13192, 13193, 13194, 13195, 13196,
13197, 13198, 13199, 13200, 13201, 13202, 13203, 13204, 13205,
13206, 13207, 13208, 13209, 13210, 13211, 13212, 13213, 13214,
13215, 13216, 13217, 13218, 13219, 13220, 13221, 13222, 13223,
13224, 13225, 13226, 13227, 13228, 13229, 13230, 13231, 13232,
13233, 13234, 13235, 13236, 13237, 13238, 13239, 13240, 13241,
13242, 13243, 13244, 13245, 13246, 13247, 13248, 13249, 13250,
13251, 13252, 13253, 13254, 13255, 13256, 13257, 13258, 13259,
13260, 13261, 13262, 13263, 13264, 13265, 13266, 13267, 13268,
13269, 13270, 13271, 13272, 13273, 13274, 13275, 13276, 13277,
13278, 13279, 13280, 13281, 13282, 13283, 13284, 13285, 13286,
13287, 13288, 13289, 13290, 13291, 13292, 13293, 13294, 13295,
13296, 13297, 13298, 13299, 13300, 13301, 13302, 13303, 13304,
13305, 13306, 13307, 13308, 13309, 13310, 13311, 13312, 13313,
13314, 13315, 13316, 13317, 13318, 13319, 13320, 13321, 13322,
13323, 13324, 13325, 13326, 13327, 13328, 13329), class = "Date"),
num_of_arrests = c(550L, 617L, 895L, 1224L, 1379L, 1246L,
893L, 635L, 889L, 1316L, 1223L, 1264L, 1258L, 852L, 478L,
710L, 1131L, 1190L, 1309L, 1085L, 910L, 704L, 852L, 1278L,
1322L, 1250L, 1128L, 967L, 686L, 812L, 998L, 1350L, 1356L,
1292L, 1006L, 568L, 867L, 1296L, 1428L, 1327L, 1182L, 821L,
233L, 618L, 915L, 1370L, 1391L, 1237L, 992L, 649L, 888L,
1167L, 1369L, 1126L, 1071L, 888L, 615L, 831L, 1019L, 1364L,
1109L, 1239L, 962L, 720L, 930L, 1233L, 1413L, 1350L, 1258L,
1034L, 629L, 954L, 1181L, 1421L, 1332L, 974L, 924L, 680L,
958L, 1232L, 1389L, 1289L, 1189L, 931L, 672L, 824L, 1188L,
1332L, 1194L, 1005L, 1011L, 653L, 822L, 1252L, 1421L, 1316L,
1231L, 902L, 740L, 811L, 1184L, 1362L, 1401L, 1144L, 860L,
383L, 775L, 1143L, 1296L, 1271L, 1056L, 729L, 593L, 836L,
1264L, 1341L, 1298L, 1127L, 771L, 548L, 908L, 1290L, 1398L,
1297L, 1127L, 878L, 663L, 928L, 1258L, 1389L, 1300L, 1135L,
937L, 600L, 851L, 1173L, 1366L, 1211L, 958L, 912L, 602L,
843L, 1274L, 1368L, 1332L, 1068L, 823L, 589L, 482L, 1076L,
1217L, 1194L, 1020L, 822L, 628L, 895L, 1225L, 1116L, 1264L,
1254L, 829L, 747L, 911L, 1241L, 1291L, 1267L, 1182L, 924L,
438L, 826L, 1228L, 1361L, 1255L, 1095L, 763L, 594L, 860L,
1056L, 1157L, 1073L, 898L)), row.names = c(NA, 181L), class = "data.frame")
To get the number of arrests per month, you could do as follows: extract the month and year by using the lubridate functions month() and year(), group by both of them (year could be omitted in your example, since there is only year 2006) and summarize() the sum().
As requested, to get a column with year and month, paste() them together, ungroup(), deselect the helper columns and relocate() yearmonth to the front.
Code
library(dplyr)
library(lubridate)
result <- data %>% mutate(year = year(ARREST_DATE), month = month(ARREST_DATE)) %>%
group_by(year, month) %>% summarise(arrests_per_month = sum(num_of_arrests)) %>%
mutate(yearmonth = paste(year, month, sep = "-")) %>% ungroup() %>%
select(-c(year, month)) %>% relocate(yearmonth)
Output
> result
# A tibble: 6 x 2
yearmonth arrests_per_month
<chr> <int>
1 2006-1 31051
2 2006-2 28872
3 2006-3 33910
4 2006-4 30541
5 2006-5 32253
6 2006-6 30414

Impose a restriction when choosing values from a dataframe

I have a dataframe which I sorted according to the columns date and adj. R&D Ratio. The first 50 rows of the dataframe looks as follows:
date stock GICS adj R&D Ratio
1 31.12.2000 DK0060336014 1510 3.2788032
2 31.12.2000 GB0002634946 2010 3.1489301
3 31.12.2000 NL0013267909 1510 1.3716449
4 31.12.2000 FR0014003TT8 4510 1.3603767
5 31.12.2000 GB00B63H8491 2010 1.2785898
6 31.12.2000 FR0013176526 2510 1.2757339
7 31.12.2000 GB0005758098 2010 1.2014918
8 31.12.2000 NL0000235190 2010 1.1203695
9 31.12.2000 CH0012255151 2520 1.0961999
10 31.12.2000 DK0060534915 3520 1.0838993
11 31.12.2000 SE0000108656 4520 1.0742266
12 31.12.2000 NL0000226223 4530 1.0637055
13 31.12.2000 NL0000009538 3510 1.0614985
14 31.12.2000 FR0000120578 3520 1.0545063
15 31.12.2000 GB0009895292 3520 1.0446137
16 31.12.2000 FR0000131906 2510 1.0350811
17 31.12.2000 DE000BASF111 1510 1.0321425
18 31.12.2000 FR0000120321 3030 1.0264104
19 31.12.2000 FR0000121972 2010 0.9888394
20 31.12.2000 BE0003470755 1510 0.9875462
21 31.12.2000 SE0000667925 5010 0.9823553
22 31.12.2000 DK0060738599 3510 0.9703896
23 31.12.2000 FR0000121329 2010 0.9353715
24 31.12.2000 GB0009252882 3520 0.9238076
25 31.12.2000 CH0012032048 3520 0.9166875
26 31.12.2000 FR0010307819 2010 0.8880829
27 31.12.2000 CH0012005267 3520 0.8654555
28 31.12.2000 AT0000746409 5510 0.8544338
29 31.12.2000 DE0006048432 3030 0.8503410
30 31.12.2000 GB00B10RZP78 3030 0.8471261
31 31.12.2000 DE0005190003 2510 0.7854462
32 31.12.2000 DE0007164600 4510 0.7837740
33 31.12.2000 SE0000115446 2010 0.7575963
34 31.12.2000 CH0418792922 1510 0.7306865
35 31.12.2000 DE0005200000 3030 0.7260179
36 31.12.2000 NL0012169213 3520 0.7173231
37 31.12.2000 IT0003828271 3520 0.6893013
38 31.12.2000 IE0004906560 3020 0.6787389
39 31.12.2000 DE0007010803 2010 0.6667161
40 31.12.2000 DK0010272632 3510 0.6535777
41 31.12.2000 FR0000120271 1010 0.6426599
42 31.12.2000 NL0000334118 4530 0.6390019
43 31.12.2000 CH0012100191 3520 0.5960179
44 31.12.2000 GB0009223206 3510 0.5941659
45 31.12.2000 SE0000695876 2010 0.5940705
46 31.12.2000 NL00150001Q9 2510 0.5835512
47 31.12.2000 CH0030170408 2010 0.5802350
48 31.12.2000 FI0009000681 4520 0.5793825
49 31.12.2000 DE0007664039 2510 0.5673987
50 31.12.2000 GB0007188757 1510 0.5402853
My aim is to choose the 30 stocks with the highest adj R&D Ratio. Therefore I use the following code:
Portfolio <- Adjusted_RD_Ratio %>% #make long pivots
arrange(date,desc(`adj R&D Ratio`)) %>% #sort by dates and score descending
group_by(date) %>% #group by dates important for next step
slice_head(n = 30) %>%
dplyr::mutate(Rank=1:30)
Additionally, I now want to impose a restriction that maximum 5 stocks out of the same GICS sector code can be choosen. When the cap for a GICS sector is achieved, the next stocks from a GICS sector which has still not achieved 5 stocks should be considered according to the descending order of the adj R&D Ratio.
Has somebody an idea of how to resolve this problem.
Thanks in advance!
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000", "31.12.2000",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001", "31.12.2001",
"31.12.2001", "31.12.2001", "31.12.2001", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002", "31.12.2002",
"31.12.2002", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003", "31.12.2003",
"31.12.2003", "31.12.2003"), stock = c("GB0007980591", "AT0000743059",
"ES0173516115", "FR0000120271", "NO0010096985", "LU1598757687",
"BE0974320526", "SE0000112724", "FR0000120073", "CH0012214059",
"NL0013267909", "BE0003470755", "CH0016440353", "DE0006047004",
"FI0009000459", "CH0010645932", "GB0007188757", "GB00B1XZS820",
"DE000BASF111", "AT0000831706", "NL0000009827", "FI0009005961",
"SE0015811559", "DE000A3E5D64", "DK0060336014", "IE00BZ12WP82",
"CH0418792922", "AT0000730007", "DE0007010803", "DE0007030009",
"FR0000121972", "FR0000125007", "SE0000667891", "DK0061539921",
"NO0003043309", "CH0001752309", "CH0002432174", "CH0006372897",
"FR0014004L86", "SE0000108227", "FI0009003727", "GB00B63H8491",
"SE0000114837", "SE0000115446", "CH0012221716", "FR0000073272",
"IE0004927939", "SE0000695876", "SE0007100581", "SE0011166610",
"GB0009465807", "CH0024638196", "CH0030170408", "GB0002634946",
"FR0000120503", "GB00BGLP8L22", "CH1101098163", "IT0001078911",
"NL0000235190", "FR0010307819", "FR0000121329", "GB0005758098",
"ES0143416115", "NL0000395903", "NO0005668905", "DE0007664039",
"DE0005439004", "FR0000121261", "FR0000131906", "NL00150001Q9",
"DE0005190003", "FR0000121147", "FR0013176526", "FI0009005318",
"SE0016589188", "FR0000130403", "DE0006969603", "DE000A1EWWW0",
"DE000A1PHFF7", "CH0012255151", "FR0000121667", "FR0000121014",
"IE00BWT6H894", "GB0033195214", "BE0974293251", "CH0010570759",
"CH0038863350", "SE0015812219", "FR0000120644", "DK0010181759",
"IE0000669501", "GB0002875804", "GB0006731235", "IE0004906560",
"FR0000120321", "DE0005200000", "DE0006048432", "GB00B10RZP78",
"SE0000202624", "DK0060738599", "DK0010272632", "DE0007165631",
"DE0005785604", "DE0005785802", "GB0009223206", "NL0000009538",
"DK0060534915", "DE000BAY0017", "CH0364749348", "DK0010272202",
"BE0003739530", "IT0003828271", "DE0006599905", "CH0012100191",
"CH0014284498", "CH0012005267", "CH0012032048", "CH0012530207",
"NL0012169213", "CH0013841017", "GB0009252882", "FR0000120578",
"GB0009895292", "DK0060495240", "DE0006452907", "DE0007164600",
"CH0012453913", "FR0014003TT8", "GB00B8C3BL03", "SE0015961909",
"SE0000108656", "GB0003308607", "FI0009000681", "NL0012866412",
"NO0003055501", "NL0000334118", "NL0000226223", "FI0009007884",
"ES0178430E18", "IT0003497168", "SE0000667925", "DE0005557508",
"NO0010063308", "DE000ENAG999", "FI0009007132", "FR0010208488",
"ES0130670112", "AT0000746409", "GB0007980591", "AT0000743059",
"ES0173516115", "FR0000120271", "NO0010096985", "LU1598757687",
"BE0974320526", "SE0000112724", "FR0000120073", "CH0012214059",
"NL0013267909", "BE0003470755", "CH0016440353", "DE0006047004",
"FI0009000459", "CH0010645932", "GB0007188757", "GB00B1XZS820",
"DE000BASF111", "AT0000831706", "NL0000009827", "FI0009005961",
"SE0015811559", "DE000A3E5D64", "DK0060336014", "IE00BZ12WP82",
"CH0418792922", "AT0000730007", "DE0007010803", "DE0007030009",
"FR0000121972", "FR0000125007", "SE0000667891", "DK0061539921",
"NO0003043309", "CH0001752309", "CH0002432174", "CH0006372897",
"FR0014004L86", "SE0000108227", "FI0009003727", "GB00B63H8491",
"SE0000114837", "SE0000115446", "CH0012221716", "FR0000073272",
"IE0004927939", "SE0000695876", "SE0007100581", "SE0011166610",
"GB0009465807", "CH0024638196", "CH0030170408", "GB0002634946",
"FR0000120503", "GB00BGLP8L22", "CH1101098163", "IT0001078911",
"NL0000235190", "FR0010307819", "FR0000121329", "GB0005758098",
"ES0143416115", "NL0000395903", "NO0005668905", "DE0007664039",
"DE0005439004", "FR0000121261", "FR0000131906", "NL00150001Q9",
"DE0005190003", "FR0000121147", "FR0013176526", "FI0009005318",
"SE0016589188", "FR0000130403", "DE0006969603", "DE000A1EWWW0",
"DE000A1PHFF7", "CH0012255151", "FR0000121667", "FR0000121014",
"IE00BWT6H894", "GB0033195214", "BE0974293251", "CH0010570759",
"CH0038863350", "SE0015812219", "FR0000120644", "DK0010181759",
"IE0000669501", "GB0002875804", "GB0006731235", "IE0004906560",
"FR0000120321", "DE0005200000", "DE0006048432", "GB00B10RZP78",
"SE0000202624", "DK0060738599", "DK0010272632", "DE0007165631",
"DE0005785604", "DE0005785802", "GB0009223206", "NL0000009538",
"DK0060534915", "DE000BAY0017", "CH0364749348", "DK0010272202",
"BE0003739530", "IT0003828271", "DE0006599905", "CH0012100191",
"CH0014284498", "CH0012005267", "CH0012032048", "CH0012530207",
"NL0012169213", "CH0013841017", "GB0009252882", "FR0000120578",
"GB0009895292", "DK0060495240", "DE0006452907", "DE0007164600",
"CH0012453913", "FR0014003TT8", "GB00B8C3BL03", "SE0015961909",
"SE0000108656", "GB0003308607", "FI0009000681", "NL0012866412",
"NO0003055501", "NL0000334118", "NL0000226223", "FI0009007884",
"ES0178430E18", "IT0003497168", "SE0000667925", "DE0005557508",
"NO0010063308", "DE000ENAG999", "FI0009007132", "FR0010208488",
"ES0130670112", "AT0000746409", "GB0007980591", "AT0000743059",
"ES0173516115", "FR0000120271", "NO0010096985", "LU1598757687",
"BE0974320526", "SE0000112724", "FR0000120073", "CH0012214059",
"NL0013267909", "BE0003470755", "CH0016440353", "DE0006047004",
"FI0009000459", "CH0010645932", "GB0007188757", "GB00B1XZS820",
"DE000BASF111", "AT0000831706", "NL0000009827", "FI0009005961",
"SE0015811559", "DE000A3E5D64", "DK0060336014", "IE00BZ12WP82",
"CH0418792922", "AT0000730007", "DE0007010803", "DE0007030009",
"FR0000121972", "FR0000125007", "SE0000667891", "DK0061539921",
"NO0003043309", "CH0001752309", "CH0002432174", "CH0006372897",
"FR0014004L86", "SE0000108227", "FI0009003727", "GB00B63H8491",
"SE0000114837", "SE0000115446", "CH0012221716", "FR0000073272",
"IE0004927939", "SE0000695876", "SE0007100581", "SE0011166610",
"GB0009465807", "CH0024638196", "CH0030170408", "GB0002634946",
"FR0000120503", "GB00BGLP8L22", "CH1101098163", "IT0001078911",
"NL0000235190", "FR0010307819", "FR0000121329", "GB0005758098",
"ES0143416115", "NL0000395903", "NO0005668905", "DE0007664039",
"DE0005439004", "FR0000121261", "FR0000131906", "NL00150001Q9",
"DE0005190003", "FR0000121147", "FR0013176526", "FI0009005318",
"SE0016589188", "FR0000130403", "DE0006969603", "DE000A1EWWW0",
"DE000A1PHFF7", "CH0012255151", "FR0000121667", "FR0000121014",
"IE00BWT6H894", "GB0033195214", "BE0974293251", "CH0010570759",
"CH0038863350", "SE0015812219", "FR0000120644", "DK0010181759",
"IE0000669501", "GB0002875804", "GB0006731235", "IE0004906560",
"FR0000120321", "DE0005200000", "DE0006048432", "GB00B10RZP78",
"SE0000202624", "DK0060738599", "DK0010272632", "DE0007165631",
"DE0005785604", "DE0005785802", "GB0009223206", "NL0000009538",
"DK0060534915", "DE000BAY0017", "CH0364749348", "DK0010272202",
"BE0003739530", "IT0003828271", "DE0006599905", "CH0012100191",
"CH0014284498", "CH0012005267", "CH0012032048", "CH0012530207",
"NL0012169213", "CH0013841017", "GB0009252882", "FR0000120578",
"GB0009895292", "DK0060495240", "DE0006452907", "DE0007164600",
"CH0012453913", "FR0014003TT8", "GB00B8C3BL03", "SE0015961909",
"SE0000108656", "GB0003308607", "FI0009000681", "NL0012866412",
"NO0003055501", "NL0000334118", "NL0000226223", "FI0009007884",
"ES0178430E18", "IT0003497168", "SE0000667925", "DE0005557508",
"NO0010063308", "DE000ENAG999", "FI0009007132", "FR0010208488",
"ES0130670112", "AT0000746409", "GB0007980591", "AT0000743059",
"ES0173516115", "FR0000120271", "NO0010096985", "LU1598757687",
"BE0974320526", "SE0000112724", "FR0000120073", "CH0012214059",
"NL0013267909", "BE0003470755", "CH0016440353", "DE0006047004",
"FI0009000459", "CH0010645932", "GB0007188757", "GB00B1XZS820",
"DE000BASF111", "AT0000831706", "NL0000009827", "FI0009005961",
"SE0015811559", "DE000A3E5D64", "DK0060336014", "IE00BZ12WP82",
"CH0418792922", "AT0000730007", "DE0007010803", "DE0007030009",
"FR0000121972", "FR0000125007", "SE0000667891", "DK0061539921",
"NO0003043309", "CH0001752309", "CH0002432174", "CH0006372897",
"FR0014004L86", "SE0000108227", "FI0009003727", "GB00B63H8491",
"SE0000114837", "SE0000115446", "CH0012221716", "FR0000073272",
"IE0004927939", "SE0000695876", "SE0007100581", "SE0011166610",
"GB0009465807", "CH0024638196", "CH0030170408", "GB0002634946",
"FR0000120503", "GB00BGLP8L22"), GICS = c(1010L, 1010L, 1010L,
1010L, 1010L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L,
1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L,
1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2020L, 2020L, 2510L,
2510L, 2510L, 2510L, 2510L, 2510L, 2510L, 2510L, 2510L, 2520L,
2520L, 2520L, 2520L, 2520L, 2520L, 2520L, 2520L, 2530L, 2550L,
3020L, 3020L, 3020L, 3020L, 3020L, 3020L, 3020L, 3020L, 3020L,
3020L, 3030L, 3030L, 3030L, 3030L, 3510L, 3510L, 3510L, 3510L,
3510L, 3510L, 3510L, 3510L, 3520L, 3520L, 3520L, 3520L, 3520L,
3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L,
3520L, 3520L, 3520L, 4510L, 4510L, 4510L, 4510L, 4510L, 4510L,
4520L, 4520L, 4520L, 4520L, 4530L, 4530L, 4530L, 4530L, 5010L,
5010L, 5010L, 5010L, 5010L, 5010L, 5510L, 5510L, 5510L, 5510L,
5510L, 1010L, 1010L, 1010L, 1010L, 1010L, 1510L, 1510L, 1510L,
1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L,
1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L,
1510L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2020L, 2020L, 2510L, 2510L, 2510L, 2510L, 2510L, 2510L,
2510L, 2510L, 2510L, 2520L, 2520L, 2520L, 2520L, 2520L, 2520L,
2520L, 2520L, 2530L, 2550L, 3020L, 3020L, 3020L, 3020L, 3020L,
3020L, 3020L, 3020L, 3020L, 3020L, 3030L, 3030L, 3030L, 3030L,
3510L, 3510L, 3510L, 3510L, 3510L, 3510L, 3510L, 3510L, 3520L,
3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L,
3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 4510L, 4510L,
4510L, 4510L, 4510L, 4510L, 4520L, 4520L, 4520L, 4520L, 4530L,
4530L, 4530L, 4530L, 5010L, 5010L, 5010L, 5010L, 5010L, 5010L,
5510L, 5510L, 5510L, 5510L, 5510L, 1010L, 1010L, 1010L, 1010L,
1010L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L,
1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L,
1510L, 1510L, 1510L, 1510L, 1510L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2020L, 2020L, 2510L, 2510L,
2510L, 2510L, 2510L, 2510L, 2510L, 2510L, 2510L, 2520L, 2520L,
2520L, 2520L, 2520L, 2520L, 2520L, 2520L, 2530L, 2550L, 3020L,
3020L, 3020L, 3020L, 3020L, 3020L, 3020L, 3020L, 3020L, 3020L,
3030L, 3030L, 3030L, 3030L, 3510L, 3510L, 3510L, 3510L, 3510L,
3510L, 3510L, 3510L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L,
3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L, 3520L,
3520L, 3520L, 4510L, 4510L, 4510L, 4510L, 4510L, 4510L, 4520L,
4520L, 4520L, 4520L, 4530L, 4530L, 4530L, 4530L, 5010L, 5010L,
5010L, 5010L, 5010L, 5010L, 5510L, 5510L, 5510L, 5510L, 5510L,
1010L, 1010L, 1010L, 1010L, 1010L, 1510L, 1510L, 1510L, 1510L,
1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L,
1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L, 1510L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L), `adj R&D Ratio` = c(0.348155241119327, 0.308311789187149,
0, 0.642659933709443, 0.362284696408923, 0, 0, 0.265064652566881,
0, 0, 1.3716448579888, 0.987546214844275, 0, 0, 0, 0, 0.540285314948445,
0.246014967343632, 1.03214245194207, 0, 0, 0, 0.38813139306808,
0.508049430058752, 3.278803238908, 0.313371910811858, 0.730686542892275,
0, 0.685094617352839, 0, 0.986658578864182, 0.209939934569318,
0.533731615464964, 0, 0, 0, 0, 0.192228213829493, 0, 0, 0, 1.27576996862804,
0.389884935527518, 0.7559254783163, 0, 0, 0, 0.592760314339032,
0.326830553905841, 0.419963119618002, 0.157465997671278, 0.308474346065886,
0.578955367565927, 3.14198530645716, 0, 0.243399720846679, 0,
0, 1.1178985422591, 0.886124286528083, 0.933308611949108, 1.19884196016655,
0, 0, 0, 0.567398706320641, 0, 0, 1.03508108032538, 0.583551165057629,
0.785446163338981, 0, 1.27573387367582, 0, 0, 0.157384430388781,
0, 0, 0, 1.09619990329866, 0, 0.117288099499881, 0, 0, 0, 0,
0.432907995571292, 0, 0.297104334427303, 0, 0, 0.164654206396396,
0.0616574435115365, 0.678738923154843, 1.02641040895497, 0.726017895208422,
0.850341015921822, 0.847126067171272, 0.280729520707776, 0.970389589309208,
0.653577670582228, 0, 0, 0.110446021210623, 0.59416587220934,
1.06149854528088, 1.08389931674238, 0.539248805707932, 0, 0.263468728853693,
0, 0.689301285790686, 0.526846235537207, 0.613801350400133, 0.329455351730347,
0.865455522409555, 0.916687482889656, 0, 0.717323050856873, 0.364810458633517,
0.923807556377483, 1.05450633395584, 1.04461369626387, 0, 0,
0.783773997697676, 0.396370333452717, 1.36037667050387, 0.477654303183566,
0.0360646916525175, 1.07422661223121, 0.377240762523683, 0.579382530689806,
0.446680920878707, 0, 0.639001944311312, 1.06370553923918, 0,
0, 0, 0.98235530252385, 0, 0, 0.265600708617901, 0, 0, 0, 0.854433767763663,
0.201927413394085, 0.274129354537357, 0, 0.47680927287233, 0.302531781574416,
0, 0, 0.192945746751328, 0, 0, 1.46263534955525, 0.952288658875395,
0, 0, 0, 0, 0.505128883590175, 0.215873962148967, 0.934894836924315,
0, 0, 0, 0.301493654663015, 0.485989797635933, 3.12257194212532,
0.311775702586192, 0.733451590567599, 0, 0.601685124231466, 0,
1.08026385220228, 0.218051857386941, 0.55856851034172, 0, 0,
0, 0, 0.0701507512256765, 0, 0, 0, 1.17153985695965, 0.546402750649552,
0.589800473197486, 0, 0, 0, 0.446615805191319, 0.337622266855034,
0.448266105001595, 0.135948341861317, 0.319018245163337, 0.696740631904583,
4.00144588515066, 0, 0.300208974607643, 0, 0, 1.23786073127374,
0.909658681216208, 0.871846217450788, 1.21973410815926, 0, 0,
1.05263157894737, 0.796341696166487, 0.796245684410749, 0, 1.03662722433986,
0.591516035043152, 0.841990318475533, 0, 1.17788594574777, 0,
0, 0.0484716788902265, 0, 0.342823132395847, 0, 0, 0, 0.0737208693391075,
0, 0, 0, 0, 0.334281730349548, 0, 0.212168879517065, 0, 0.0343201969475623,
0.114102616805445, 0.0386057502830502, 0.475998376860053, 0.766062211525202,
0.493537738022368, 0.639927261544939, 0.557185345643263, 0.325386086922749,
0.880107755827675, 0.593197579885409, 0.667250813965762, 0.205289682856566,
0.0895971132362813, 0.573868081473294, 1.2490069686656, 1.10385280671179,
0.56567580491217, 0, 0.699294346437204, 0, 0.471918248076076,
0.49579258545322, 0.785964208161947, 0.308875000991175, 0.875169473473618,
0.882493788984404, 0, 0.670912988984689, 0.269303486595569, 0.82438407477315,
1.05052713746408, 1.09502168818641, 0.358529337103318, 0, 0.641046573016473,
0.718440957294033, 1.46926507117661, 0.54180725824382, 0.0565251549655809,
1.08535607397206, 0.300004199661506, 0.516315580824989, 0.408049566606371,
0, 0.933727056747273, 1.01169522527989, 0, 0, 0, 0.55508363946608,
0.453935481796046, 0, 0.339717575869076, 0, 0, 0, 0.0224159466567322,
0.238326175524057, 0.281633191906362, 0, 0.400903843039083, 0.23633700026716,
0, 0, 0.155782009690722, 0.253589106251182, 0, 1.42573034675602,
1.10289757392777, 0.820958198286726, 0, 0.121243485954335, 0,
0.401853298599386, 0.176328771471093, 0.771205919719764, 0, 0,
0, 0.228503333899315, 0.485760891836534, 2.81558930126304, 0.294532824977541,
0, 0, 0.755170639318799, 0, 1.08103823610396, 0.21354647402288,
0.579503100339761, 0, 0, 0, 0, 0.0800925897730931, 0, 0, 0, 1.06325037456255,
0.552399355502998, 0.65312561277287, 0, 0, 0, 0.504288948870772,
0.349931432625589, 0.392093839174648, 0.136285237477173, 0.337073135197932,
0.56407493700002, 4.11286855185496, 0.281322434520689, 0.359937879417767,
0, 0, 1.45249010632265, 0.969763800057246, 0.80251763830963,
1.17955545828545, 0, 0, 1.05263157894737, 0.927066526472698,
0.844185952173605, 0, 0.616750924915803, 0.595220672513441, 0.986082016872856,
0, 1.15403108317551, 0, 0, 0.055910225080283, 0, 0.309451802101752,
0, 0.831521835559022, 0, 0.0879392874947248, 0, 0, 0, 0, 0.323665374288555,
0, 0.233024445765765, 0, 0.056207036565913, 0.123197095688553,
0.0313521066253501, 0.49646315780896, 0.779562187915442, 0.465769196872944,
0.637018245580238, 0.57368119779029, 0.241812505225029, 0.583924104558891,
1.40499366743767, 0.406252907662551, 0.154742075922361, 0.0785348679592576,
0.464913731136435, 0.805003049011491, 0.974988442719951, 0.533653277021197,
0, 1.17811715148882, 0, 0.437309299538281, 0.497656851639223,
0.678371898006081, 0.288808784309066, 0.835472095971294, 0.886671141826413,
0, 0.578872913702843, 0.195940508478262, 0.838696519213617, 1.00321976873748,
1.05527623134355, 0.289120415984064, 0, 0.670163085528901, 0.65339576406265,
1.54972819078517, 0.572536385751392, 0.0436549782043242, 1.08357444497098,
0.312680391134772, 0.526411478497764, 0.265403132516072, 0.0651659617812408,
1.00754954212556, 0.957219261288471, 0, 0, 0, 0.46593716924571,
0.398113183196323, 0, 0.252856571472995, 0, 0, 0, 0.0252135796317245,
0.167448066460122, 0.27484449895293, 0, 0.358193899145724, 0.206757300588434,
0, 0.219763407371917, 0.150443968793461, 0.242185024660507, 0,
1.47355352272133, 1.15909231861372, 0.736560941449678, 0, 0.143973217975224,
0, 0.352427474755206, 0.190789261817793, 0.71794103213898, 0,
0, 0, 0.2132739424551, 0.470744782765732, 2.73994933900873, 0.289702542048908,
0, 0, 0.755973395699601, 0, 1.06080329618206, 0.19498164397433,
0.541958621909451, 0, 0, 0, 0, 0.144853400240604, 0, 0, 0, 0.938554810908235,
0.432521947927588, 0.702478826332285, 0, 0, 0, 0.498973877476859,
0.350000211731058, 0.371015411278701, 0.148823783006403, 0.343394792573242,
0.556472496679883, 3.85095094444878, 0.0699049459274819, 0.335619027919786
)), row.names = c(NA, 500L), class = "data.frame")
I will first create a column GICS_count indicating the number of times a GICS code appears. Then use filter to keep those that is less than 6.
The first 10 rows of the output is pasted here for reference.
library(tidyverse)
df %>%
group_by(GICS) %>%
mutate(GICS_count = seq(1, n())) %>%
filter(GICS_count < 6) %>%
ungroup() %>%
arrange(date,desc(`adj R&D Ratio`)) %>%
slice_head(n = 30) %>%
group_by(date)
# A tibble: 30 × 5
# Groups: date [1]
date stock GICS `adj R&D Ratio` GICS_count
<chr> <chr> <int> <dbl> <int>
1 31.12.2000 DK0060336014 1510 3.28 1
2 31.12.2000 GB0002634946 2010 3.15 1
3 31.12.2000 NL0013267909 1510 1.37 2
4 31.12.2000 FR0014003TT8 4510 1.36 1
5 31.12.2000 GB00B63H8491 2010 1.28 2
6 31.12.2000 FR0013176526 2510 1.28 1
7 31.12.2000 GB0005758098 2010 1.20 3
8 31.12.2000 NL0000235190 2010 1.12 4
9 31.12.2000 CH0012255151 2520 1.10 1
10 31.12.2000 DK0060534915 3520 1.08 1

How to add a string column by category to a dataframe?

I have this dataframe with two columns, one index and one date.
Input
I would like to add another column of sequences, the column will contain 20 x "C" and 10 x "Fo" for each index, if an index has more or fewer rows, that sequence will be limited or extended while maintaining the periodicity.
Output
My daset
df = structure(list(Index = c(4885L, 4885L, 4885L, 4885L, 4885L, 4885L,
4885L, 4885L, 4885L, 4885L, 4885L, 4885L, 4885L, 4885L, 4885L,
4885L, 4885L, 4885L, 4885L, 4885L, 4885L, 4885L, 4885L, 4885L,
4885L, 4885L, 4885L, 4885L, 4885L, 4885L, 4885L, 5109L, 5109L,
5109L, 5109L, 5109L, 5109L, 5109L, 5693L, 5693L, 5693L, 5693L,
5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L,
5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L,
5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L, 5693L,
5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L,
5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L,
5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L, 5986L,
5986L, 5986L, 5986L, 5986L), date = structure(c(18892, 18896,
18900, 18904, 18908, 18912, 18916, 18920, 18924, 18928, 18932,
18936, 18940, 18944, 18948, 18952, 18956, 18960, 18964, 18968,
18972, 18976, 18980, 18984, 18988, 18992, 18996, 19000, 19004,
19008, 19012, 18893, 18897, 18901, 18905, 18909, 18913, 18917,
18891, 18895, 18899, 18903, 18907, 18911, 18915, 18919, 18923,
18927, 18931, 18935, 18939, 18943, 18947, 18951, 18955, 18959,
18963, 18967, 18971, 18975, 18979, 18983, 18987, 18991, 18995,
18999, 19003, 19007, 19011, 18892, 18896, 18900, 18904, 18908,
18912, 18916, 18920, 18924, 18928, 18932, 18936, 18940, 18944,
18948, 18952, 18956, 18960, 18964, 18968, 18972, 18976, 18980,
18984, 18988, 18992, 18996, 19000, 19004, 19008, 19012), class = "Date")), row.names = c(560L,
564L, 568L, 572L, 576L, 580L, 584L, 588L, 592L, 596L, 600L, 604L,
608L, 612L, 616L, 620L, 624L, 628L, 632L, 636L, 640L, 644L, 648L,
652L, 656L, 660L, 664L, 668L, 672L, 676L, 680L, 957L, 961L, 965L,
969L, 973L, 977L, 981L, 1842L, 1846L, 1850L, 1854L, 1858L, 1862L,
1866L, 1870L, 1874L, 1878L, 1882L, 1886L, 1890L, 1894L, 1898L,
1902L, 1906L, 1910L, 1914L, 1918L, 1922L, 1926L, 1930L, 1934L,
1938L, 1942L, 1946L, 1950L, 1954L, 1958L, 1962L, 2827L, 2831L,
2835L, 2839L, 2843L, 2847L, 2851L, 2855L, 2859L, 2863L, 2867L,
2871L, 2875L, 2879L, 2883L, 2887L, 2891L, 2895L, 2899L, 2903L,
2907L, 2911L, 2915L, 2919L, 2923L, 2927L, 2931L, 2935L, 2939L,
2943L, 2947L), class = "data.frame")
Plan = c(rep("C",20), rep("FO",20))
Any suggestion?
We can use rep after grouping by 'Index'
library(dplyr)
df <- df %>%
group_by(Index) %>%
mutate(Seq = rep(rep(c("C", "Fo"), c(20, 10)), length.out = n())) %>%
ungroup
-output
df
# A tibble: 100 × 3
Index date Seq
<int> <date> <chr>
1 4885 2021-09-22 C
2 4885 2021-09-26 C
3 4885 2021-09-30 C
4 4885 2021-10-04 C
5 4885 2021-10-08 C
6 4885 2021-10-12 C
7 4885 2021-10-16 C
8 4885 2021-10-20 C
9 4885 2021-10-24 C
10 4885 2021-10-28 C
# … with 90 more rows

Measure Accuracy errors print NA

I'm building ARIMA model on my data and when I try to check the Measure Accuracy errors , it print NA!
I don't know where I missed up.
Does any one have suggestions please ?
accuracy(forecast_data, test_data)
$Models
Call $Fit.criteria
"Min.max.accuracy MAE MAPE MSE RMSE NRMSE.mean NRMSE.median
"Not supported" NA NA NA NA NA NA NA
"Not supported" NA NA NA NA NA NA NA
"Not supported" NA NA NA NA NA NA NA
"Not supported" NA NA NA NA NA NA NA
Here's my code:
auto_ARIMA <- auto.arima(training_data, trace=TRUE, ic ="aicc", approximation=FALSE, stepwise=FALSE)
forecast_data <- forecast(object=test_data, model= auto_ARIMA)
accuracy(forecast_data, test_data)
my data is in Time series format and has no NA..
Any help will be appreciated.
updates:
Here's part of what dput(training_data) & dput(test_data) print:
dput(training_data)
c(601L, 215L, 147L, 275L, 707L, 1509L, 2118L, 1506L, 1439L, 1745L,
1882L, 1773L, 1752L, 1773L, 1727L, 1823L, 1860L, 2020L, 1744L,
1670L, 1498L, 1372L, 1262L, 723L, 313L, 166L, 129L, 252L, 695L,
1510L, 2051L, 1484L, 1417L, 1838L, 1756L, 1740L, 1756L, 1675L)
dput(training_data)
c(601L, 215L, 147L, 275L, 707L, 1509L, 2118L, 1506L, 1439L, 1745L,
1882L, 1773L, 1752L, 1773L, 1727L, 1823L, 1860L, 2020L, 1744L,
1670L, 1498L, 1372L, 1262L, 723L, 313L, 166L, 129L, 252L, 695L,
1510L, 2051L, 1484L, 1417L, 1838L, 1756L, 1740L, 1756L, 1675L)

Resources