I understand that this question has been asked before but I could not solve the question with the current solutions after searching.
I am running into an error:
Error in solve.default(covs) :
system is computationally singular: reciprocal condition number = 1.08804e-18
Code: (which give the error)
library(lpSolve)
retbar <- colMeans(rets, na.rm = T)
covs <- var(rets, na.rm = T) # calculates the covariance
invS <- solve(covs)
Other:
> det(covs)
[1] 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003458185
> qr(covs)$rank
[1] 20
However when I remove some variables and run the code it works....
Code2: (which works)
rets$B6 <- NULL
rets$M6 <- NULL
rets$R6 <- NULL
rets$Q6 <- NULL
retbar <- colMeans(rets, na.rm = T)
covs <- var(rets, na.rm = T) # calculates the covariance
invS <- solve(covs)
> det(covs)
[1] 0.000000000000000000000000000000000000000000000000000000000000000000000000003514001
> qr(covs)$rank
[1] 20
I just want to understand why removing "X6" variable from my data allows me to solve the cov matrix. I have seen that "X6" (X here is B,M,R,Q) is correlated with other variables - "X6" is calculated as "X5 - X1" (or: B5 -B1, M5 - M1, R-5 - R1, Q5 - Q1") - I would like to idealy keep all columns in the data.
Data:
EDIT: New df
rets <- structure(list(B1 = c(0.0201596769556875, 0.00796992085297743,
0.0492147329548896, 0.019344865533839, 0.0215214485329025, 0.0207218693128776,
0.0103862072924815, 0.0140747415980048, 0.0261785500777131, 0.0373946762995772,
-0.00684759663692184, -0.0524902194742576, 0.00315800118629925,
0.0311087399558667, 0.0296245772665513, -0.0714423815378389,
-0.00828133058937649, -0.0474562526488911, -0.027177578320533,
-0.0150494495620104, 0.0348119470955449, 0.026557944400082, -0.0948970420281616,
0.020249494359762, 0.0362642768918328, -0.108930302464037, -0.209399350620045,
-0.131078973014079, 0.0340021699340833, -0.0392411420552388,
-0.104669817843903, 0.126868769506696, 0.180232948671053, 0.0769264211043898,
0.019176729939273, 0.0993469049194573, 0.0738823618605167, 0.0686517377053094,
-0.0438445535170806, 0.0291731714634921, 0.074704119945333, -0.00156713313391479,
0.041919134266091, 0.0718713711298, 0.0616824041447802, -0.0694331912797978,
-0.0664994905875237, -0.0637350113576239, 0.0995459645599069,
0.0350470019423567), B2 = c(0.0159402689787551, 0.0162507344633192,
0.0740337591014227, 0.0384769820770539, 0.0091777285515574, 0.0266077913225889,
0.0135757617808849, 0.00407485086602279, 0.024561373325238, 0.0369076019690258,
-0.0111998096779211, -0.0550216348217377, 0.00296776607315141,
0.0155911183644963, 0.0127829585460845, -0.0686988206697129,
-0.0120169929067047, -0.0379441518196964, -0.00997556953482333,
-0.0157591765829324, 0.0259378688367708, 0.0348720134553493,
-0.0864851422178537, 0.0243151482365286, 0.054450975569433, -0.105384283400191,
-0.244132080369671, -0.149214851674911, 0.0642730083371614, -0.0732165541787947,
-0.132146613068358, 0.117037257468365, 0.243486361548774, 0.127689400206569,
0.0507680353897798, 0.0918127231182545, 0.057623460462537, 0.0664555639592365,
-0.0637209916042463, 0.0351111011481844, 0.0774253568342104,
-0.0208447613007578, 0.0464411219167523, 0.088343873921378, 0.0845804848931461,
-0.0672340736611374, -0.063074008563108, -0.0552850698211716,
0.118020745550881, 0.0350453682926441), B3 = c(0.0254691625247841,
0.0122239330016886, 0.0446599436180717, 0.0289436320423226, 0.00984126934358344,
0.0248495851877287, 0.0070023062540998, 0.00867717868910234,
0.0198468884639984, 0.0423526987264829, -0.00673483175868612,
-0.0536716292198917, 0.00702602564601019, 0.0161515106339872,
0.00881414723751897, -0.0704128768108256, -0.0118703057246587,
-0.0654796158401091, -0.0214858440189339, -0.0287089650155394,
0.0375015423973781, 0.0669904486938052, -0.0941557378605896,
0.0153425838301645, 0.0209397917472626, -0.101627763946357, -0.226324878317675,
-0.141233587277128, 0.0562599340844954, -0.0426624056954274,
-0.101409613365061, 0.095072163016385, 0.19560509325657, 0.153377825232805,
0.0250685160313996, 0.0912032732747058, 0.0514030426458047, 0.0803912808233686,
-0.0604690113263003, 0.0268422517753881, 0.10412185199629, -0.0227046178907074,
0.045247514742643, 0.080985450832222, 0.0646318077059794, -0.0703469469216747,
-0.0487479424020042, -0.0677789445266782, 0.102936536920121,
0.0372798264656416), B4 = c(0.0219191738217161, 0.0176853257846887,
0.0456353457446462, 0.0341367113786865, 0.0224113039756616, 0.0198275955536373,
0.00679047712618314, 0.00326894704835364, 0.0279149805055439,
0.0270857608217435, -0.00413393714898988, -0.0566739462091404,
-0.0114439339594225, 0.011077534748248, 0.0166466370578447, -0.0733647442632695,
-0.0100085083715353, -0.0525145185232886, -0.0326582904953551,
-0.0193272575954162, 0.028187178228298, 0.037490075562138, -0.0740065271333753,
0.0376882236271473, 0.0170308927355229, -0.0991359056176541,
-0.224423397219161, -0.118318357393019, 0.0765578429241032, -0.0580225262433487,
-0.110441975119102, 0.101623526281797, 0.208245933500372, 0.0931300452658907,
0.0371493076663389, 0.109834174058939, 0.0451845252205385, 0.0922986324245771,
-0.0604417879228685, 0.0176772270368012, 0.0760699055274017,
-0.0219431067610276, 0.0363180693269241, 0.10978144288715, 0.0703026600940392,
-0.0827017008478804, -0.0577866241297221, -0.0682246277864018,
0.112824937430707, 0.042166109959073), B5 = c(0.0393541248460465,
0.00956169994553254, 0.045506941231113, 0.022679161458704, 0.0071175687346599,
0.0245724846722118, -0.00486326015007488, 0.00977777199018314,
0.0372227348807343, 0.0421686696514302, -0.00729705359364536,
-0.0420398232585704, -0.00198560837531052, 0.0191012049979939,
0.0151182378767174, -0.0720890664222317, -0.0145999296151926,
-0.0549852597740717, -0.0357418224487, -0.00858510372461121,
0.0371052230990963, 0.0358706764622103, -0.0797211143737148,
0.0133179042163717, 0.0227502855968991, -0.0960364954219236,
-0.20877985810845, -0.125247884467955, 0.0582827803341161, -0.0546479539249937,
-0.127419512889315, 0.161520030974712, 0.213080660094016, 0.108923963868525,
0.0216324723000225, 0.123493437786137, 0.0643989332634697, 0.065803254107272,
-0.0624072744596408, 0.0370168039973202, 0.0836690142031841,
-0.0128692586306809, 0.0506633041324735, 0.0963571736706436,
0.0704426407884252, -0.0733420360542838, -0.0710357171347283,
-0.0688377671567964, 0.132571567141589, 0.0447762558807919),
B6 = c(0.019194447890359, 0.00159177909255511, -0.0037077917237766,
0.00333429592486495, -0.0144038797982426, 0.00385061535933419,
-0.0152494674425564, -0.00429696960782166, 0.0110441848030212,
0.00477399335185296, -0.000449456956723525, 0.0104503962156872,
-0.00514360956160977, -0.0120075349578728, -0.0145063393898339,
-0.00064668488439279, -0.00631859902581606, -0.00752900712518056,
-0.00856424412816701, 0.00646434583739916, 0.00229327600355132,
0.00931273206212835, 0.0151759276544468, -0.00693159014339035,
-0.0135139912949337, 0.0128938070421132, 0.000619492511594932,
0.00583108854612438, 0.0242806104000329, -0.0154068118697549,
-0.0227496950454118, 0.0346512614680161, 0.0328477114229624,
0.0319975427641352, 0.00245574236074952, 0.0241465328666802,
-0.00948342859704696, -0.00284848359803735, -0.0185627209425603,
0.0078436325338281, 0.00896489425785109, -0.0113021254967661,
0.00874416986638248, 0.0244858025408436, 0.008760236643645,
-0.00390884477448601, -0.00453622654720459, -0.00510275579917252,
0.0330256025816826, 0.00972925393843514), M1 = c(0.0113396747037768,
-0.036155735142529, 0.0550687853246927, 0.0269238017499447,
0.00982287898659706, 0.00809061527252197, -0.047512024641037,
-0.016009446233511, -0.00278357416391373, -0.00628054095432162,
-0.0609199032187462, -0.0494923722396639, 0.00698078286246139,
0.00983662394804645, 0.0380059639114982, -0.0652908706460783,
-0.00563693966137906, -0.0491752210641838, -0.0214304637710383,
-0.0153438172807354, 0.0203537379326515, 0.0421207453446271,
-0.083814601712769, 0.0152837951106913, 0.031787003709805,
-0.107241585677281, -0.210874717399826, -0.115555851834153,
0.0599437241751638, -0.0587498251989018, -0.0995314111424103,
0.104148721637336, 0.182319135902193, 0.105787461175244,
0.033689877375748, 0.0966363048202885, 0.0640538126301515,
0.0640782744095522, -0.0440799278693556, 0.0303018999590801,
0.0841023643583563, -0.0176897923202359, 0.0382914170044418,
0.0759079900327234, 0.0738894489211014, -0.0566797658200011,
-0.0592523659979936, -0.0605415574124922, 0.108837738508142,
0.0311480459267166), M2 = c(0, 0.0369318500161171, 0.05479446798563,
0.0441558659076691, 0.0063580423593521, -0.0073090447112918,
-0.0191763313487172, -0.00646415911614895, 0.0458552502095698,
0.0275424104183912, -0.0487805381417274, -0.0400584393734526,
-0.00416827541765468, 0.0212708574224962, 0.0174144436427715,
-0.0674113624348997, -0.0125841060695098, -0.0558416555270291,
-0.0163345211185515, -0.0219548647100168, 0.0504916901610439,
0.0417230815077788, -0.0769711063634779, 0.0167976787218786,
0.0430265647426742, -0.123826423650743, -0.234415110641567,
-0.130708167875127, 0.0554669174895657, -0.0450817684669273,
-0.12032524188012, 0.154298987141929, 0.236011380184834,
0.114111615690755, 0.0275421794934158, 0.0938332458107501,
0.0953365754115465, 0.0847282442055681, -0.0712375521873279,
0.0174096324909712, 0.0755245202122583, -0.00762107035320276,
0.0428905926947967, 0.0972422302671232, 0.076027299598966,
-0.0788738990751014, -0.0621384863719475, -0.0624743295694587,
0.116711918883773, 0.0476898780038488), M3 = c(0.0359311569482088,
-0.139999955892563, 0.0209301561117172, 0.104783609509468,
-0.0721649304032326, 0.397777765989304, -0.0111288027837873,
0.00482318503782153, 0.14879997074604, 0.16648281365633,
-0.0580596011132003, -0.047679182583228, 0.0114269531841602,
0.0317433578864438, 0.00775221147687179, -0.061602244912588,
-0.0158776681251565, -0.0648263710640019, -0.0240124892502704,
-0.0177448932428571, 0.0379559719894449, 0.0344511040566261,
-0.0775795445422815, 0.027065822418437, 0.0251577377516715,
-0.108475149947571, -0.235411574529894, -0.144522154940724,
0.0449754514928253, -0.0489695645129837, -0.123624581783743,
0.11508095146038, 0.211242172822533, 0.145198421859061, 0.0179784820325099,
0.0982173541566308, 0.0555486086463638, 0.0736606557016785,
-0.0583725513432673, 0.0363466235082538, 0.0690110039168571,
-0.0160342605855651, 0.0540222033909931, 0.0862467848463471,
0.0633677104077289, -0.0850614424954192, -0.0535852042349274,
-0.0603007163253751, 0.113070077846931, 0.0408424520012463
), M4 = c(-0.155844137072563, -0.0610789265483618, 0.0988630047067999,
-0.0086556291207671, 0.0815064907073975, -0.0185706592164934,
-0.0207591075450184, 0.105547562241554, -0.107201084494591,
0.0113929212093353, -0.022529099136591, -0.0441186886312525,
0.00195441980877977, 0.016870060442579, 0.00759373951839394,
-0.0769912599379698, -0.0171198804233096, -0.0417608516722064,
-0.0238246997368977, -0.0177104066632295, 0.0235756050630395,
0.0269268993848493, -0.0967296211775303, 0.0324606583258286,
0.0290416693746976, -0.092120191410525, -0.230766838669409,
-0.140616977306715, 0.0699212552919189, -0.0613821172279649,
-0.129080012361016, 0.115632295353163, 0.241743159430643,
0.0945421887374065, 0.0330785879111653, 0.114030935722985,
0.0394783260686381, 0.0637947810755577, -0.060909434465672,
0.0323739642311314, 0.0841339563067396, -0.0184345132038895,
0.0495400154798214, 0.0976821368464078, 0.0614972022290451,
-0.0706658855287132, -0.070385725555342, -0.073441507572736,
0.109315224489104, 0.0374856931309638), M5 = c(-0.12346476316452,
-0.0105703119188547, 0.092919297516346, 0.136621922254562,
-0.0155999753624201, 0.0682649463415146, -0.0922404378652573,
0.0620875768363475, -0.0615064632147553, 0.143709745258093,
0.0756230279803276, -0.0617075127175431, -0.00360911323150503,
0.0112366336242249, 0.0154406559539872, -0.0787746054515343,
-0.00269523979941826, -0.0526490888305032, -0.0326128715360069,
-0.0167875265945536, 0.0288873225335168, 0.0437001503452364,
-0.0850432923719407, 0.0182440995488183, 0.0238926558011993,
-0.0957959717629556, -0.215013577753659, -0.144644269534711,
0.0501889619753152, -0.05768291939606, -0.128211720987334,
0.127069415092379, 0.216602876296358, 0.113530188173674,
0.0468711288658715, 0.122424450357045, 0.0374143540121529,
0.0871767761121666, -0.0567737247714127, 0.0360353329323981,
0.103461599696569, -0.0225164942232245, 0.0415910101081693,
0.0918531230749919, 0.0755528541988306, -0.0728917148203065,
-0.0657610368590244, -0.0564028779478209, 0.122215778161083,
0.045920382671152), M6 = c(-0.134804437868297, 0.0255854232236743,
0.0378505121916533, 0.109698120504617, -0.0254228543490172,
0.0601743310689926, -0.0447284132242203, 0.0780970230698586,
-0.0587228890508416, 0.149990286212415, 0.136542931199074,
-0.0122151404778793, -0.0105898960939664, 0.00140000967617841,
-0.0225653079575109, -0.0134837348054559, 0.00294169986196079,
-0.00347386776631942, -0.0111824077649687, -0.00144370931381818,
0.00853358460086529, 0.00157940500060929, -0.00122869065917164,
0.00296030443812702, -0.0078943479086057, 0.011445613914325,
-0.00413886035383279, -0.0290884177005585, -0.00975476219984855,
0.00106690580284179, -0.0286803098449235, 0.0229206934550435,
0.0342837403941652, 0.00774272699843015, 0.0131812514901235,
0.0257881455367569, -0.0266394586179985, 0.0230985017026144,
-0.0126937969020571, 0.00573343297331802, 0.0193592353382127,
-0.00482670190298854, 0.00329959310372758, 0.0159451330422685,
0.00166340527772912, -0.0162119490003055, -0.0065086708610308,
0.00413867946467136, 0.0133780396529413, 0.0147723367444354
), Q1 = c(0.0265621797051281, 0.0121992440563654, 0.0340947461024625,
0.0114726169959482, 0.0244721697934678, 0.0304556573852703,
-0.00256444356341105, 0.00372350399549636, 0.0237739984235116,
0.0270033285140239, -0.00704723803210073, -0.0476901397804718,
0.0071129609034004, 0.0323939519651734, 0.00323882454019589,
-0.0622794850397196, -0.0119234506451499, -0.0399236912960561,
-0.0436079844051925, -0.0261022150048638, 0.0291371183325865,
0.0563959058031636, -0.0907071155080928, 0.013374178530945,
0.0681693173169967, -0.0880869802416643, -0.218258767247561,
-0.138316280509299, 0.0411314660955931, -0.066409005195869,
-0.139430000425292, 0.101716784591166, 0.199285888061083,
0.0893195469347605, 0.0207835902897264, 0.0819590143972909,
0.0428754482336569, 0.0804621560497635, -0.0576983031786784,
0.026600132264742, 0.0760024661290204, -0.0281950326994129,
0.0424528139477703, 0.0865725399565793, 0.077255839460645,
-0.0690729842646359, -0.0617721764311835, -0.0619110102090971,
0.0975149637737052, 0.0422298654882387), Q2 = c(0.0265492763632932,
0.0222894305734672, 0.0476030515586719, 0.0257378459646134,
0.0255000609197377, 0.0300794550319551, 0.0133745468006092,
0.0187672452778894, 0.0248004048250247, 0.0205707288256205,
-0.00587681182154011, -0.0630040478242402, 0.000107261570787615,
0.00467345834692457, 0.0213892270033362, -0.0937099313495658,
0.00251645909947125, -0.0632956599325149, -0.00132090380066074,
-0.031540190910209, 0.0415217259003839, 0.0196243224662538,
-0.0976611527880924, 0.01713131867179, 0.0206693921571488,
-0.10984720875515, -0.23604335413059, -0.123298519500156,
0.102579391798905, -0.0619608930031467, -0.122741970750742,
0.107440420011137, 0.258562571065352, 0.0831288756533286,
0.0380738103365828, 0.102122914387041, 0.0771691647838361,
0.0869058388988892, -0.0542813220308744, 0.0351488706963522,
0.0846733840829011, -0.0167029370619785, 0.0380128870131627,
0.0954233112213096, 0.059146453231235, -0.0675340663722515,
-0.0772898672570218, -0.0756378709511565, 0.134937047612454,
0.0226618044495643), Q3 = c(0.0249571957657415, 0.0296065641893266,
0.0516467535933711, 0.0204032773069533, 0.00564130011432592,
0.0224283534635712, 0.00301239166268108, -0.000150963898842058,
0.0229134533635214, 0.0424657574061316, -0.00777680567175671,
-0.0445223698536066, 0.00394081997679386, 0.0240830812307228,
0.0124971211046563, -0.0795800732459543, -0.00881168550209076,
-0.0584900388668757, -0.0263079088348604, -0.0200931730088996,
0.0449965138077459, 0.0368462420389372, -0.114047989403222,
0.0267671234829322, 0.0151821869391063, -0.111191677522722,
-0.204383997931583, -0.126313542632778, 0.0672104859243762,
-0.0666682464928415, -0.0980276147276163, 0.109471163679627,
0.194550998802703, 0.0833334999543796, 0.0343969262838429,
0.0992981119758178, 0.0528223219283973, 0.0674760505087006,
-0.0665537698263506, 0.0342528662929908, 0.0958234167504998,
-0.0294131255411294, 0.0476092755160584, 0.0909138728225699,
0.0727903652909526, -0.0637077652670556, -0.0656483788804145,
-0.0551227529131964, 0.116486035743042, 0.0356988697476277
), Q4 = c(0.0327908558900147, -0.00581402105550901, 0.0471795087541677,
0.0316287353740667, 0.0154292859732494, 0.0321233577293451,
0.0178516903431687, 0.0297250315289144, 0.0497392455796797,
0.0539487711478713, 0.00185283865199054, -0.0550304813356512,
0.0242636750567233, 0.0215392546950305, 0.0293588232816546,
-0.0724868968014562, -0.000755860281788007, -0.0471606758364942,
-0.0207128138943517, -0.0165231425832055, 0.0434456925169798,
0.0391054884659545, -0.0742084088275147, 0.017590121803775,
0.0469003681911008, -0.096158440258061, -0.226202925207553,
-0.115346873402837, 0.0553655066805321, -0.0526318049432673,
-0.0854428438991429, 0.154789113362523, 0.20641849783792,
0.178990423471939, 0.0210107589738628, 0.1585673924883, 0.0698894288055367,
0.109538887119296, -0.0571717024643894, 0.0429703488688447,
0.0646785154424408, -0.0175924605503971, 0.0516479415292585,
0.106135927417663, 0.0894213136540906, -0.0842766439587239,
-0.0607679109495784, -0.064878143379156, 0.12349074462156,
0.0383776279423885), Q5 = c(0.0277489582011476, 0.0194428538125939,
0.0464771821653864, 0.0257204433555745, -0.000805859957640792,
0.0258752236753201, 0.00169526561907242, 0.00845686232849219,
0.0248138846673567, 0.0499029147276336, -0.026119026588276,
-0.0506759613875208, -0.0186567955284256, 0.00666071759448302,
0.00540296976899718, -0.0716488022451813, -0.0217757529500649,
-0.0338310975042987, -0.0341928029469273, -0.0223690567604255,
0.02094411401049, 0.0387905936222523, -0.0834270093258965,
0.0341064407380287, 0.00713508490452064, -0.127295832074014,
-0.237585142941304, -0.13633100805025, 0.0404317628621166,
-0.0701342930682682, -0.154994464337936, 0.137138389891867,
0.266473867978314, 0.149346235523739, 0.0512020926289552,
0.0972987430985086, 0.046678198308291, 0.0691887409841002,
-0.0483228606644157, 0.0438380166785084, 0.108567878481663,
-0.022344000031356, 0.0458931252688222, 0.0821382803979602,
0.0776712501269335, -0.0782288163911569, -0.0717866494829638,
-0.0441555801962854, 0.113855257071555, 0.0431730594966379
), Q6 = c(0.00118677849601953, 0.00724360975622851, 0.0123824360629239,
0.0142478263596263, -0.0252780297511086, -0.00458043370995016,
0.00425970918248347, 0.00473335833299583, 0.00103988624384509,
0.0228995862136097, -0.0190717885561753, -0.00298582160704901,
-0.025769756431826, -0.0257332343706903, 0.00216414522880129,
-0.00936931720546169, -0.00985230230491503, 0.00609259379175739,
0.00941518145826525, 0.00373315824443837, -0.00819300432209647,
-0.0176053121809113, 0.00728010618219631, 0.0207322622070837,
-0.0610342324124761, -0.0392088518323502, -0.0193263756937437,
0.00198527245904931, -0.00069970323347647, -0.00372528787239923,
-0.0155644639126446, 0.0354216053007016, 0.0671879799172312,
0.0600266885889786, 0.0304185023392288, 0.0153397287012177,
0.00380275007463411, -0.0112734150656633, 0.00937544251426276,
0.0172378844137663, 0.0325654123526421, 0.00585103266805692,
0.00344031132105193, -0.00443425955861904, 0.000415410666288515,
-0.00915583212652102, -0.0100144730517803, 0.0177554300128117,
0.0163402932978495, 0.000943194008399206), R1 = c(0.0182182283776942,
0.0133596019044421, 0.0432659004262889, 0.0221001061009796,
0.0105907624828407, 0.0239597644983188, 0.000582050596458943,
0.014147774983186, 0.0234533732901644, 0.0317608721171364,
-0.0166806564027188, -0.052434190706138, 0.0100713259540498,
0.0101734290645623, 0.0288354928293034, -0.0605050812338745,
-0.0117308063666151, -0.0572323586752662, -0.0272877553780779,
-0.0120147655606391, 0.0419646855503247, 0.0324565952813083,
-0.0993208162860145, 0.0395097806733453, 0.0238556437261408,
-0.114658174673633, -0.2195395447872, -0.137508094828707,
0.074964741726552, -0.0604685437878159, -0.111606039290815,
0.136833144806414, 0.222703023385423, 0.0841373058009376,
0.0141210132573047, 0.0945658775885383, 0.0720258311603175,
0.072218863181222, -0.0464783244216175, 0.0196372191978457,
0.0764585826402174, -0.0109085058330569, 0.0359374463515418,
0.0818041172339742, 0.0660486282980199, -0.0707042835229565,
-0.0683338724528508, -0.0610787198706517, 0.10245202132339,
0.0336024502788171), R2 = c(0.0191115892525381, 0.0213770552106516,
0.0495591080020083, 0.0217964101541805, 0.0144038778845475,
0.0184814835192124, 0.0105638044882981, 0.0169188201074749,
0.0276594408901124, 0.0348981320533056, -0.00601471285249273,
-0.0742367928195745, 0.00395378441574753, 0.0204693427515786,
0.0119432134599844, -0.0874038103063021, -0.0151874175793209,
-0.0472985114867765, -0.0280096128634695, -0.0160812378016462,
0.0321308743545342, 0.040546940059076, -0.0948356372283535,
0.0107826096321911, 0.0257959865133892, -0.111356276103297,
-0.231763659704638, -0.114593808207563, 0.0521066918649241,
-0.0585007082261173, -0.109123376446412, 0.126602824255329,
0.173736381165564, 0.199924017362175, 0.0481556947170322,
0.0973811981639015, 0.0359796749373038, 0.0813126198664245,
-0.0512295355950761, 0.0279254079344163, 0.086866979370594,
-0.0192548779536499, 0.0447691648075989, 0.0862634325791489,
0.0697143276875948, -0.0692263805833664, -0.0500105867630836,
-0.0588590458196327, 0.106730721635263, 0.0421188281435415
), R3 = c(0.0127029458612358, 0.0018533759915124, 0.0760172229180238,
0.0367249979117247, 0.0150598922914917, 0.0336805265497945,
0.00793725637078958, 0.00747404394924289, 0.0274879617237065,
0.043333103669918, -0.00161559239160282, -0.0455316266423957,
-0.00214711870702203, 0.0248726461836401, 0.00653189279270605,
-0.0578474430051428, -0.00753182224084245, -0.0497961950688571,
-0.0215957843383809, -0.0186999944968934, 0.0484307593124901,
0.0311984415753566, -0.0821598079518168, 0.0100672285713556,
0.0372802787529577, -0.104028042014104, -0.222058497109385,
-0.147313185333738, 0.058569009115331, -0.044662665977512,
-0.109997225946555, 0.0740040206123078, 0.240124115068233,
0.0658274676989834, 0.0230167129023561, 0.0893684046831913,
0.0691791022696998, 0.0935037055760548, -0.0623467636644952,
0.0443609426523667, 0.0841050150254741, -0.010595198663421,
0.0531204943650837, 0.0889886676318655, 0.0717397607923485,
-0.0666121329043526, -0.0679554782502061, -0.0619185083705071,
0.113668574986972, 0.0426805703464197), R4 = c(0.0380760367129327,
0.0177375553170367, 0.0434032638099822, 0.0288078728030292,
0.00992978596216649, 0.0292202896891021, 0.0000603359551190975,
0.0159922639270591, 0.0343884360605202, 0.0439464803116257,
-0.0138187383575441, -0.0420847227142335, -0.00232802864713809,
0.0234398999431073, 0.0192280943826554, -0.0652622771727051,
-0.0129287081223056, -0.0621169225429621, -0.0188534586231707,
-0.0144850139328243, 0.0297268555763311, 0.0285599283377065,
-0.0822735971636855, 0.0204183204990269, 0.032745768708656,
-0.105603577501441, -0.221743181027705, -0.13083768618741,
0.0451022094242408, -0.0511348958540317, -0.117597592112605,
0.135103916679692, 0.220409599165432, 0.123643858561056,
0.0412763113887445, 0.114076890036475, 0.0618001339957569,
0.0751807434389775, -0.0761590390584388, 0.0367453217535741,
0.0741501663098758, -0.0209351147382463, 0.0423510899687777,
0.100368821441917, 0.0695076535685885, -0.0721797128413838,
-0.0600897558968101, -0.0664215180686919, 0.128039957194454,
0.0470262161757679), R5 = c(0.0392411376774867, 0.0154176355104196,
0.040917916701852, 0.0218273582628919, 0.0129334794884874,
0.0272767829214404, 0.00362824471430165, -0.000676154777673734,
0.0324915392070016, 0.0312519866611661, -0.00752454226284161,
-0.0479068156734558, 0.00623306676125675, 0.0175638068591043,
0.0180622711059288, -0.0716966531562826, -0.0105557651114313,
-0.0470363381042701, -0.0319284024370003, -0.0274867890109039,
0.0328552378238075, 0.0503210109454812, -0.0847538417074522,
0.0213618251884607, 0.0268119067996639, -0.0900801570280097,
-0.229113867007717, -0.128659614134882, 0.0757805549254453,
-0.0540399315416828, -0.121830787213285, 0.122317733604241,
0.218198170804459, 0.0991190501510919, 0.0380010340764608,
0.119750604540555, 0.0560657704951905, 0.0599450854028368,
-0.0472973800122937, 0.0261746785776476, 0.0965835597718561,
-0.025910690013656, 0.0420420706295301, 0.101981995863621,
0.0648998978320577, -0.0930218340085276, -0.0682703531336771,
-0.0717185642128733, 0.123732482524253, 0.0358365680790375
), R6 = c(0.0210229092997925, 0.00205803360597752, -0.0023479837244369,
-0.000272747838087638, 0.00234271700564669, 0.00331701842312161,
0.00304619411784271, -0.0148239297608598, 0.00903816591683728,
-0.000508885455970276, 0.00915611413987719, 0.00452737503268219,
-0.00383825919279309, 0.00739037779454201, -0.0107732217233747,
-0.0111915719224081, 0.00117504125518384, 0.0101960205709961,
-0.00464064705892239, -0.0154720234502648, -0.00910944772651717,
0.0178644156641729, 0.0145669745785623, -0.0181479554848846,
0.00295626307352316, 0.024578017645623, -0.00957432222051705,
0.00884848069382546, 0.000815813198893262, 0.00642861224613316,
-0.0102247479224694, -0.0145154112021735, -0.00450485258096373,
0.0149817443501543, 0.0238800208191561, 0.0251847269520169,
-0.015960060665127, -0.0122737777783852, -0.000819055590676188,
0.00653745937980193, 0.0201249771316388, -0.0150021841805991,
0.0061046242779883, 0.020177878629647, -0.00114873046596223,
-0.0223175504855711, 0.0000635193191737132, -0.0106398443422216,
0.0212804612008627, 0.00223411780022038)), row.names = c(NA,
-50L), class = "data.frame")
Firstly, nothing in the question has anything to do with lpSolve or with retbar so please remove this junk from the question.
covs is singular so it cannot be inverted. Note the essentially zero eigenvalues below. Evidently the columns that are linearly dependent on the remaining columns are those set to NULL so removing them eliminates the singularity. If a Moore-Penrose generalized inverse is sufficient then MASS::ginv(covs) could be used.
covs <- var(rets, na.rm = TRUE)
eigen(covs)$values
giving the following eigenvector which includes 4 near zeros:
[1] 1.147251e-01 4.508339e-03 3.566784e-03 9.437460e-04 6.489510e-04
[6] 4.975564e-04 3.300602e-04 2.840001e-04 2.674243e-04 2.202487e-04
[11] 1.428033e-04 9.985863e-05 9.513909e-05 7.955750e-05 6.892488e-05
[16] 5.715785e-05 4.055359e-05 3.127846e-05 2.710167e-05 6.273551e-06
[21] 6.322894e-19 2.240421e-19 -3.041137e-19 -9.827006e-19