My data frame consists of variable gene expression values recorded at two time points for one of three groups ( either control which is 0, ulcerative colitis which is 1 and Crohns which is 2). Where the ID is the same number, the top value is the first time point and the second value is the second time point.
Please find below my data frame to help explain;
Dput(data)
structure(list(X = c(0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 0, 0, 2, 2,
1, 1, 0, 0, 0, 0, 2, 2, 1, 1, 2, 2), ID = c(44, 44, 68, 68, 77,
77, 119, 119, 453, 453, 654, 654, 776, 776, 888, 888, 876, 876,
899, 899, 901, 901, 987, 987, 990, 990), Gene1 = c(5.54e-05,
5.58e-06, 9.74e-05, 1.33e-06, 1.29e-05, 7.22e-06, 0.000215899,
3.6e-06, 0.000146724, 1.53e-05, 0.000913187, 1.9e-06, 0.007421464,
0.000648006, 5.1e-06, 6.15e-06, 4.73e-06, 0.000119899, 0.000884487,
0.000850632, 0.000236607, 7.36e-06, 8.48e-06, 2.63e-05, 0.001368493,
1.12e-05), Gene2 = c(0.006338532, 0.006162866, 0.040695132, 0.013255055,
0.033086619, 0.074158811, 0.004967497, 0.01247423, 0.043201417,
0.011470285, 0.038447751, 0.018825124, 0.027701807, 0.063373762,
0.005374513, 0.048876252, 0.009959848, 0.004434078, 0.004176856,
0.015288913, 0.060226053, 0.05128922, 0.006557554, 0.017460326,
0.007684784, 0.002107577), Gene3 = c(0.076186393, 0.037631043,
0.052159393, 0.012179365, 0.047199766, 0.022458838, 0.030261613,
0.00626629, 0.028664896, 0.02285845, 0.02801855, 0.017681676,
0.040563592, 0.029791175, 0.034778056, 0.019318473, 0.011847912,
0.009614177, 0.064027542, 0.035334149, 0.041638955, 0.056015014,
0.03304865, 0.017660205, 0.030187166, 0.057919531), Gene4 = c(0.000112884,
0.000920886, 0.001081748, 0.000195159, 0.001678445, 0.000171612,
0.000191702, 0.000560035, 0.000384056, 0.000454783, 0.000723385,
0.000203897, 0.000973337, 0.000822171, 0.000620526, 0.000260769,
0.000214607, 0.002077443, 0.00065843, 0.000403672, 0.000378651,
0.000409306, 0.001722587, 0.000213785, 0.000176643, 0.002022878
), Gene5 = c(0.053029236, 0.022594965, 0.011967636, 0.026851113,
0.03773798, 0.031356268, 0.10410326, 0.063265216, 0.018028454,
0.116038001, 0.00572817, 0.053635968, 0.059126941, 0.011835241,
0.004639624, 0.014302911, 0.082948853, 0.015202238, 0.021295431,
0.043342, 0.008153675, 0.015613747, 0.043289609, 0.048834321,
0.019144763, 0.059809871), Gene6 = c(0.04082966, 0.02986135,
0.061405171, 0.006142619, 0.009767602, 0.035427993, 0.03729329,
0.01309739, 0.00221718, 0.040211393, 0.006303841, 0.030146612,
0.032033879, 0.024590398, 0.077991721, 0.017215666, 0.014731147,
0.04802582, 0.03168714, 0.03244771, 0.032278613, 0.017301885,
0.013450667, 0.040207755, 0.042669615, 0.03456749), Gene7 = c(1.93e-05,
4.72e-06, 5.41e-05, 0, 1.91e-05, 9.33e-07, 5.98e-06, 0, 1.05e-06,
4.1e-07, 7.72e-05, 4.07e-07, 0.000585154, 0.000246992, 7.86e-06,
3.13e-06, 2.14e-06, 7.56e-06, 9.29e-05, 0.000116024, 5.51e-05,
7.79e-06, 6.65e-06, 2.06e-06, 0.000104342, 4.16e-06), Gene8 = c(0.000197502,
0.00015135, 0.000107306, 6.54e-05, 0.000225564, 0.000142631,
0.000168873, 3.5e-05, 0.000365242, 0.000174254, 0.000339327,
8.7e-05, 0.000136679, 0.000156634, 0.000224181, 0.000205305,
8.87e-05, 0.000305774, 0.000133615, 0.00015118, 0.000107229,
0.000162579, 0.000152249, 6.88e-05, 0.000113864, 0.000249258),
Gene9 = c(0.00079296, 0.007640951, 0.004937327, 0.000422361,
0.000953513, 0.000951187, 0.000671306, 0.001106406, 0.002606568,
0.003006867, 0.001911646, 0.00135411, 0.012461738, 0.000434917,
0.00237646, 0.007857561, 0.000436889, 0.00048816, 0.000348146,
0.000931449, 0.000323974, 0.004945321, 0.000693845, 0.000479572,
0.000843415, 0.001419675), Gene10 = c(8.16e-05, 6.63e-05,
0.000101583, 3.08e-05, 0.000147039, 5.13e-05, 0.000109479,
2.39e-05, 0.000225475, 4.28e-05, 0.000230785, 2.1e-05, 0.0001356,
0.000124173, 0.000245128, 0.000275446, 3.18e-05, 0.00017516,
0.000180192, 0.000246669, 0.000378708, 4.35e-05, 0.000267824,
7.2e-05, 7.65e-05, 8.79e-05), Gene11 = c(0.000111462, 3.17e-05,
0.000200096, 3.12e-06, 8.75e-05, 3.11e-06, 6.89e-06, 0.000165936,
5.98e-05, 0.000201355, 5.92e-06, 2.57e-05, 2.53e-05, 3.27e-05,
0.000137446, 0.000134402, 5.86e-07, 3.9e-05, 0.018886909,
0.050343466, 4.15e-05, 1.67e-05, 0.000172614, 4.95e-05, 1.27e-05,
9.85e-05), Gene12 = c(0.002708402, 0.003215586, 0.00457116,
0.001713549, 0.024353184, 0.006660748, 0.003198887, 0.003094386,
0.004789163, 0.002816955, 0.021587313, 0.002084725, 0.00378062,
0.021751495, 0.009097143, 0.012216225, 0.001125765, 0.013043534,
0.005514773, 0.008323962, 0.026898764, 0.002149135, 0.008021623,
0.006673567, 0.005391139, 0.018578559), Gene13 = c(0.00080595,
0.001289505, 0.002451416, 0.000234107, 0.001694733, 0.000288175,
0.002357478, 0.000856129, 0.00159752, 0.000117538, 0.000166581,
0.000367288, 0.001039841, 0.001779528, 0.000438092, 0.001012515,
0.000529936, 0.003193086, 0.002562702, 0.00277401, 0.003013136,
0.001349197, 0.001646296, 0.001114222, 0.001207882, 0.002804949
)), class = "data.frame", row.names = c(NA, 26L))
I have calculated the distance between the samples using this code;
distances <- as.matrix(vegdist(data[,3:15], method="euclidean", diag=F))
I now need to formulate a table, where each of the three columns (corresponding to either control, ulcerative colitis or Crohn’s) contains the distances between the first and second-time points.
So control will have 5, UC will have 4 and Crohn’s will have 4.
I understand that I will need a for loop and will need to also use if. I am struggling as to where to start with this. Please could anybody advise?
Update;
Can also use the usedist package in R and use dist_get
distances<-dist_get(distance.matrix, origin, destination)
And define the origin and destination accordingly, depending upon which rows you need to get the distance value from.
I would like to plot the SAT dataset found here
https://blog.prepscholar.com/sat-percentiles-high-precision-2016
My issue with doing this is that I am unsure if there is a more elegant way to do this than I am doing. Currently, I am converting those percentiles to Z scores and then using that associated probability to create a distribution. The problem that I have is
The SAT scores do not seem to be normally distributed. They approximate a normal distribution, but they do not seem to be normally distributed. This makes using the tried and true rnorm (X, mean = 1000, sd = 200) unusable.
I am not sure if there is a better way than converting the percentiles to Z scores since the SAT scores do not seem to be normally distributed.
Any help would be appreciated.
My long term plan is to create a shiny ap where a person can use a slider to move along the distribution to see where their score puts them in what percentile. But the first step is to actually figure out a way to produce an accurate distribution.
Here is the code in total:
scores <- as.numeric(
c(
1600, 1593, 1587, 1580, 1573, 1567,
1560, 1553, 1547, 1540, 1533, 1527,
1520, 1513, 1507, 1500, 1493, 1487,
1480, 1473, 1467, 1460, 1453, 1447,
1440, 1433, 1427, 1420, 1413, 1407,
1400, 1393, 1387, 1380, 1373, 1367,
1360, 1353, 1347, 1340, 1333, 1327,
1320, 1313, 1307, 1300, 1293, 1287,
1280, 1273, 1267, 1260, 1253, 1247,
1240, 1233, 1227, 1220, 1213, 1207,
1200, 1193, 1187, 1180, 1173, 1167,
1160, 1153, 1147, 1140, 1133, 1127,
1120, 1113, 1107, 1100, 1093, 1087,
1080, 1073, 1067, 1060, 1053, 1047,
1040, 1033, 1027, 1020, 1013, 1007,
1000, 0993, 0987, 0980, 0973, 0967,
0960, 0953, 0947, 0940, 0933, 0927,
0920, 0913, 0907, 0900, 0893, 0887,
0880, 0873, 0867, 0860, 0853, 0847,
0840, 0833, 0827, 0820, 0813, 0807,
0800, 0793, 0787, 0780, 0773, 0767,
0760, 0753, 0747, 0740, 0733, 0727,
0720, 0713, 0707, 0700, 0693, 0687,
0680, 0673, 0667, 0660, 0653, 0647,
0640, 0633, 0627, 0620, 0613, 0607,
0600, 0593, 0587, 0580, 0573, 0567,
0560, 0553, 0547, 0540, 0533, 0527,
0520, 0513, 0507, 0500, 0493, 0487,
0480, 0473, 0467, 0460, 0453, 0447,
0440, 0433, 0427, 0420, 0413, 0407,
0400
)
)
probs <- as.numeric(
c(
0.000665335, 0.001508711, 0.002067932, 0.002878073, 0.003976493, 0.005137125,
0.006483906, 0.008169371, 0.010066473, 0.012051019, 0.014095858,
0.016307247, 0.01851226, 0.020808986, 0.023364025, 0.02601564,
0.028721866, 0.031560739, 0.034551519, 0.037733663, 0.041036965,
0.044427406, 0.047928757, 0.051538726, 0.055292787, 0.059145645,
0.063187376, 0.067367682, 0.071691308, 0.076255174, 0.080943422,
0.085690142, 0.090464868, 0.095379534, 0.100511283, 0.105758358,
0.111083521, 0.116571178, 0.122285078, 0.128123463, 0.13397113,
0.139830118, 0.145699225, 0.151666124, 0.157793404, 0.164023115,
0.170358704, 0.17676173, 0.183278673, 0.189955902, 0.196651135,
0.203363202, 0.210071134, 0.216801722, 0.223562248, 0.230347853,
0.237183732, 0.243934459, 0.250657665, 0.257436698, 0.264227682,
0.270968969, 0.277599004, 0.284165141, 0.290648753, 0.297040829,
0.303401865, 0.30964291, 0.315714288, 0.321696268, 0.3275473,
0.33324613, 0.338771004, 0.344104024, 0.34924206, 0.354185931,
0.358956451, 0.363504804, 0.36782396, 0.371962147, 0.375851065,
0.37943538, 0.382754048, 0.38580143, 0.388568593, 0.391025026,
0.393142417, 0.394947023, 0.39643261, 0.397582763, 0.398388967,
0.398835641, 0.398933788, 0.398676885, 0.398065535, 0.397089484,
0.395745285, 0.394041326, 0.391951596, 0.389478503, 0.386655445,
0.383491062, 0.379943329, 0.376014793, 0.371758542, 0.367167906,
0.362242796, 0.356970877, 0.351398549, 0.345499578, 0.33929925,
0.332851353, 0.326122779, 0.31911459, 0.311858166, 0.304408822,
0.296767961, 0.288895933, 0.280893084, 0.272865458, 0.264642129,
0.256259902, 0.247931807, 0.239607, 0.231228792, 0.222875786,
0.214544714, 0.206273084, 0.198003801, 0.189731661, 0.181671447,
0.173826196, 0.16610093, 0.158499433, 0.151067478, 0.143751108,
0.136558209, 0.129683746, 0.123040703, 0.11660098, 0.110455988,
0.104559737, 0.098857524, 0.093254931, 0.087923914, 0.08286171,
0.077907056, 0.073124914, 0.068583012, 0.064242767, 0.059980362,
0.055906234, 0.052062062, 0.048298984, 0.044678669, 0.041258641,
0.03796372, 0.034841037, 0.03185105, 0.028992313, 0.026330747,
0.023870486, 0.0215867, 0.019418127, 0.017379035, 0.015436224,
0.01358768, 0.011905384, 0.01032104, 0.008865584, 0.007564083,
0.006380472, 0.005299104, 0.004317991, 0.003512008, 0.00284036,
0.002268168, 0.001724469, 0.001327348, 0.001030367, 0.000112
)
)
data <- as.data.frame (cbind (scores, probs))
data2 <- sample (data$scores, 10000000, replace = T, prob = data$probs)
den <- density (data2, adjust = 2)
plot (den , xlim = c(400,1600))
I have the following problem. Basically I have data, that follows the Gregorian calendar and data, which follows a 360 day calendar and a 365 day calendar (no leap years). Its a feature of the Model, which provides the data. I only could create a timeindex for data with a 360 or 365 day calendar with the help of library(PCICt), therefore the timeindex is of class PCICt and not class date for those data sets with 360d or 365d calendars.
I managed to change the class of the timeindex of data with a 365 day calendar easily, because it always missed the 29th February. Overall it has less days than data with a Gregorian calendar, thats why the following code worked:
index(Modellwind.IPSL.1971_2100.mat.5.zoo) <- as.Date(paste(index(Modellwind.IPSL.1971_2100.mat.5.zoo), "%Y-%m-%d"))
class(index(Modellwind.IPSL.1971_2100.mat.5.zoo))
any(is.na(Modellwind.IPSL.1971_2100.mat.5.zoo))
I could merge data with a Gregorian calendar with data with a 365 day calendar (Modellwind.IPSL.1971_2100.mat.5.zoo has a 360d calendar) with the following code:
library(zoo)
library(PCICt)
Mergedata.Gregorian_cal.365d_cal <- merge(Modellwind.1971_2100.mat.5.zoo[,1],Modellwind.IPSL.1971_2100.mat.5.zoo[,1], fill = NA)
sum(is.na(Mergedata.Gregorian_cal.365d_cal)) #Gives you the number of leap years between the starting date and end date. Between 1971 and 2100, you have 32 leap years.
The problem is, that the 360 day calendar has 30 days per month. Because the 30th February doesnt exist, I cant use the method above. Is there the possibility to use the index of the data set with a Gregorian calendar, to mask the days in the data with a 360 days calendar, which arent present in the data with a Gregorian calendar? I would have NA for the 31th for each month in the data with a 360 day calendar, which has 31 days and the 30th of February would always be excluded/"deleted".
Example data for the year 1972 for all these 2 calendar types. 1972 is a leap year.
Data with Gregorian calendar:
structure(c(18.0824119718086, 22.0984972927228, 15.6444417189609,
5.89666444009656, 18.1725165479582, 21.9512885928156, 4.88193965506205,
13.933395151291, 13.0150555148858, 12.2412020084762, 15.1707058527428,
11.9102181846508, 11.8373087451369, 4.88134153024087, 3.9195944541078,
8.15191977152853, 16.4878972832708, 22.3388856060094, 24.9339938808775,
9.40486557731387, 3.28778357417694, 5.4431969404311, 20.9010729191345,
21.576769300227, 23.5252763396514, 18.7725442737342, 19.7400816746119,
16.9286422645386, 11.5214494652195, 12.6356049638603, 7.8885628659944,
7.81687922456664, 4.76970848125104, 4.71443717941174, 4.3332862268629,
5.39949220500925, 17.2259740635503, 8.94893163333614, 10.5413637024979,
7.17270151460124, 13.1168987701018, 7.80375818376942, 9.19842495123789,
6.50186468363422, 2.72654917702192, 4.76044540462425, 9.33231780065151,
2.94546305078892, 4.67014980066904, 23.8062593679947, 20.0513022569902,
17.0747102447771, 22.1857749192152, 16.3213003571625, 5.59820337769238,
11.7719699596263, 2.80575446040357, 6.01800547567089, 8.40297112483879,
11.8088715968982, 4.98554106381165, 4.57889903991417, 5.46723000525948,
2.2046248257294, 6.50476062233784, 5.93160587570127, 2.66548923257402,
6.18402932922427, 6.90886137443288, 3.85090651354255, 8.24126904737149,
10.9654562975344, 26.2730566456532, 20.7006666233841, 6.82182724533744,
12.9025799024923, 9.59995956664874, 18.3086576464973, 8.53427988021107,
13.5057006787102, 2.58426562914531, 4.77444858313551, 4.01236032427182,
11.972201385, 19.541507043929, 12.7122726666622, 6.58520942950129,
10.0492820845097, 5.32566668447011, 2.57782664078923, 7.15092309537708,
13.5172698318347, 14.9398233030208, 14.5222484425227, 8.00143290635926,
11.5258287774697, 6.38313299466099, 1.79298307790425, 4.16626735598483,
10.4754961358211, 7.29533307327725, 6.14846988554932, 12.0495274648323,
5.53397133979113, 8.37782693478431, 7.52399322022154, 13.8764650137859,
10.9413294317165, 5.79402371881772, 7.61939719880655, 2.01218529630289,
4.15345219536974, 9.53346680530963, 14.4880341424594, 6.6395383447145,
12.2147086716578, 8.61151331855143, 4.96406162861823, 2.31444711425824,
9.18479155288269, 14.0394170749205, 12.9045375342084, 8.56014631714993,
4.45030804438492, 4.54819424494151, 9.14814577436106, 9.0203698734204,
6.67536854576542, 9.86685350667901, 15.9765223111542, 1.99936492761379,
6.05549611543566, 8.26375285688692, 12.5235986676351, 15.753125460594,
12.8737600421306, 16.0142537420495, 19.6491102126186, 8.91315893820258,
5.75924709992013, 8.67418792548294, 8.36985128360697, 10.5301033184449,
7.51027331456462, 5.64433360963038, 8.25879595299386, 11.1260560553349,
7.56823816330665, 4.03999047793942, 2.81275010350658, 7.50072029786943,
6.58751650188931, 4.69084765180419, 2.37774148302349, 0.88406335422542,
1.27681388119446, 7.38546258354973, 7.36477953003889, 3.58214484416496,
9.33399864014572, 9.33384978115708, 3.75564662489672, 5.86615895989352,
11.3163675166137, 8.89088851209378, 4.83661603649021, 11.4775955585757,
8.10159661929649, 9.25168563140256, 16.8836969171831, 6.71441561265801,
8.94010341793042, 7.48206041367068, 7.85296846107665, 4.56322967848792,
3.94854955874465, 9.03935129713431, 6.80925025513715, 5.46249642897673,
2.72994386661837, 5.81781746717527, 3.58557872362357, 2.65017962257611,
10.9264114121261, 25.1233976430826, 10.9044779304577, 6.34084805815993,
13.2469244191216, 12.5438867673809, 6.69512144534366, 7.9716973798577,
6.42699271186533, 7.34127100087814, 9.48351531950429, 3.731756550704,
2.97235842074357, 9.33755238371563, 8.45534306181479, 9.76758605452981,
7.10973204410344, 5.58659570577684, 6.73065557918815, 2.2443822565949,
10.0324385505791, 12.4468029449543, 8.54955485805234, 7.74625286400315,
8.76361852142208, 7.31040726702086, 10.9069555344467, 20.2240593355273,
18.8325145078602, 13.8646347231803, 6.18721686089014, 5.06959205667858,
1.88326841118378, 3.46887269480676, 10.466733322762, 10.0359820698446,
11.6007096598598, 9.40090116780089, 9.33769236702315, 9.95757914421451,
8.55990604010644, 10.4960731180582, 15.1722236227608, 11.1686532067003,
12.5359489386538, 9.08166190238287, 3.05025798629833, 8.2121249493627,
13.5877493909831, 17.366136605839, 10.1228300566323, 8.27402110802059,
9.36245413432149, 8.46450110123141, 1.84281651654745, 3.30160338329847,
6.3138195121321, 11.728173138611, 10.6622626897554, 16.4094777741508,
20.0381278953011, 19.9861861731441, 14.5139852521008, 5.48642303877599,
7.72640073447677, 6.40813436142624, 1.68384368141763, 4.77881376279741,
5.18058883352236, 2.98929028921609, 4.63220103226812, 4.16738796400037,
13.0532771268428, 7.3104783906477, 2.22615400974864, 2.64542408728002,
7.21256528138117, 14.5616168774743, 6.49359376934273, 1.80947777511883,
1.05548742272005, 10.0100349138233, 12.9534450881407, 7.3887732493981,
2.06346550336316, 8.31717299234876, 7.78924597525132, 2.52953776616571,
8.82704926761683, 17.6640298084431, 13.3475985590147, 17.628200973858,
21.7018534179796, 18.5008930385254, 10.1186544078028, 20.3816253684839,
24.926808778224, 21.9880227371171, 20.1845589773564, 16.8169067228104,
10.2309882726068, 11.1248083859065, 20.5125621219226, 16.2733638505053,
18.8559651435026, 9.34653256821625, 16.1736806222654, 15.2975717551524,
14.5146239904197, 5.49088884606638, 10.6410636803798, 23.2390025461356,
17.9439644921709, 30.2719783889658, 17.8897458886807, 21.8089336705463,
21.181790238746, 7.74189585366475, 15.5669977526734, 22.2278845648006,
24.8537097755812, 23.4403701940983, 21.6831582162925, 2.51132630151019,
5.92677645017391, 10.9441543623409, 2.36029949616021, 1.16606557900293,
3.50793234808807, 9.61440088811323, 14.137409810834, 18.381771312848,
12.6572683827955, 18.797705699369, 20.8717521227799, 20.2278258689499,
12.9121727366459, 12.4660577833913, 19.7783723336818, 21.467091272057,
19.825201185869, 21.5289275033657, 25.2513848648435, 19.3231430907612,
14.4548913656037, 18.1364925154159, 25.6372229193355, 10.7132780942731,
3.39420618551996, 18.5659343284766, 21.7217416658684, 18.5067855518246,
17.6834051522095, 15.6325986696431, 11.6100239010514, 15.0764596715006,
8.46048294087618, 19.6747151949836, 10.0466139442861, 7.41836369302161,
19.4712502377319, 15.3111265245001, 6.54184803095167, 3.95906471757932,
4.6122997606339, 7.13881563394315, 2.48477412801708, 6.19131168025857,
7.82629557777152, 8.93410147891196, 6.27319459383102, 4.05195951965034,
8.77535610150876, 8.45968682510812, 6.27599562509301, 5.11571448525756,
1.68865280924914, 14.4333064594824, 20.5250630694977, 24.0600954370164,
13.4110946493079, 2.92078462265695, 9.06322147728374), index = structure(c(730,
731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743,
744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756,
757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769,
770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782,
783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795,
796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808,
809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821,
822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834,
835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847,
848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860,
861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873,
874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886,
887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899,
900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912,
913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925,
926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938,
939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951,
952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964,
965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977,
978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990,
991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002,
1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013,
1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024,
1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035,
1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046,
1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057,
1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068,
1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079,
1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090,
1091, 1092, 1093, 1094, 1095), class = "Date"), class = "zoo")
Data with 360 day calendar:
structure(c(16.2042726556084, 5.54411632675392, 8.39523962307452,
12.9056155820263, 2.61097842984656, 5.36226881021485, 6.11436671091439,
7.80097325957491, 2.6959250785196, 1.21734133687523, 9.83094824076473,
14.6123034310063, 22.5841804523832, 18.878943978969, 21.5918638597738,
21.6111797366467, 12.163190670239, 13.0688120229195, 13.1780838331026,
10.4636228871236, 24.5866766742838, 17.6333887432414, 13.5573702722517,
9.98750262602645, 6.60239076617993, 7.99851427184562, 10.7241814973962,
2.59032350802315, 11.0385501186685, 15.0489298603359, 8.01940878027097,
8.69182806695981, 16.4062789963677, 23.1456317293811, 26.5321804559772,
23.0561436633882, 26.6478272830746, 26.6213654159103, 17.8004617644568,
18.8721032889994, 19.0042310175412, 21.9278326697278, 20.3999804074965,
21.9715743408936, 18.1198929013236, 20.8010363608164, 16.2125640673085,
22.7866237759357, 25.7292529258921, 19.9958794890251, 18.256654841611,
26.5258848098581, 19.3699454096059, 10.2084937593693, 7.09411455312409,
11.1030076686983, 11.1372661762985, 3.46190062236435, 5.55418460608178,
7.97804690731097, 5.74135886926954, 7.37374922730165, 21.7072129639493,
22.3394149773537, 17.3029303467921, 3.78355687861244, 8.13184139976328,
5.59325194224167, 9.29484012593814, 6.31433046860712, 8.99969159771701,
12.9220576129017, 13.5931259265605, 3.13177632385839, 7.32634431180194,
3.65530722032479, 7.76414703436829, 8.81357616532502, 14.9915407274787,
15.6823286541919, 21.5504858786041, 5.98962336278648, 9.25806031602314,
15.3209102337594, 4.04377735300356, 5.57011616118502, 3.48142109034957,
3.33545016672156, 7.59622387150862, 6.33767973617138, 7.16777319213806,
11.6789745144836, 7.23398806122294, 8.42213573928181, 11.3854021290453,
8.0042725442433, 11.5874660430518, 7.59304392685827, 10.1325170959459,
9.43772890502225, 10.7429797911477, 8.98128618812878, 6.14861396465088,
3.3215569997678, 1.89256021088976, 7.7206472451583, 5.95522013274502,
1.70416254271118, 3.19059648186347, 12.7030870584645, 8.26968478768532,
6.41344157071221, 5.87633507183265, 5.49327509833653, 7.25912268522123,
14.1030446717508, 10.3857928070863, 1.78946477125607, 2.19269825383753,
5.36239917538602, 8.04801122336692, 9.13772174676138, 8.76030055066657,
5.24974918237121, 6.78870121691905, 6.33999578227359, 5.30281113218906,
3.30221973820352, 2.60392067446298, 1.53111462102273, 6.46313647857284,
5.41150103883632, 7.30461939054954, 1.31915479430045, 9.9035310971835,
17.5782680328385, 6.84670227987107, 6.11975680612864, 5.41175515673305,
1.96524773901671, 8.72579457176407, 14.8123207565971, 12.3543611734912,
12.5322670823202, 7.31607993610375, 4.88025074826665, 9.2349041842484,
12.8681772530755, 11.6570687183401, 11.3849275808392, 5.08995224957851,
11.7893280264097, 12.0657931400087, 3.90848586347189, 6.66831144616517,
13.0856694686881, 9.54256465111552, 12.8039726978337, 10.5409569683412,
6.2013575567933, 6.76347346611077, 8.01227281098426, 6.67880581810349,
1.87696959195576, 4.26549311170547, 6.0882073470888, 6.12735098378745,
3.77616335435411, 3.75627711831876, 2.42781407431047, 2.27015239785359,
8.49280126151322, 6.3855458158828, 7.55076769935463, 2.31943333528733,
8.61089385566335, 4.14893952705846, 7.1125243515635, 10.093324208137,
12.8925732478462, 8.38797653985974, 7.47214225316014, 3.01447415423619,
3.1124918239105, 0.997851709938026, 3.09921928374142, 6.93293196431786,
7.36267778624579, 1.6137886634392, 7.42809062139576, 10.1127101736776,
7.53648374651043, 9.3498729537249, 5.98534661771884, 3.62870605159867,
3.53073240568869, 10.6964068541091, 11.3646789054076, 13.6494798740885,
9.76353695866836, 4.1270448976489, 7.18525843242649, 14.6971093432512,
14.6412126138519, 10.3400082940444, 12.7842963215163, 15.0888363759895,
15.6640254377632, 7.23691815389075, 8.81381770055476, 10.4784236463785,
6.23389999515105, 9.40862295199213, 13.041974380848, 7.75158030116834,
10.6893999091349, 16.1456445166579, 14.9041082855705, 11.884570665801,
6.53019503138492, 8.45239632750322, 3.7455743269618, 7.12180323764388,
6.61415344272644, 8.13149697512074, 9.36721511760265, 6.95717437071885,
5.73006255663904, 11.0494713342971, 11.328774774157, 12.1912982708966,
7.22849562327449, 12.1251543738353, 8.31581645241497, 17.9662467445553,
20.7050537175761, 9.36158364710033, 11.3278809607471, 7.33435422138495,
3.10786053234989, 5.33073248829936, 9.06872903556503, 15.8831247239495,
15.2818041038765, 9.50926214591815, 5.15112388784473, 13.1166042461675,
21.3933111639123, 14.7608935887845, 6.08300197048536, 2.54102181247197,
11.0248978300555, 13.0216530977284, 12.6537314347268, 16.8215177071213,
18.1193743387326, 13.8658700430018, 2.87800172912917, 7.58969180535585,
15.6024741775647, 20.569775255989, 14.0528170625014, 9.86770039714737,
10.2081826678756, 5.37219506560582, 8.56141023229151, 9.91834375772563,
12.82212567194, 10.7507818184859, 4.15008765939222, 10.2404428622595,
3.80299439427962, 5.16901081513056, 4.4821661216413, 3.26656062260985,
4.43932965953986, 8.945663203153, 11.3165820526751, 20.8820331492001,
9.98917730606554, 7.55099134175274, 10.4150732881417, 13.2278295764203,
18.1688812620581, 14.1445620735261, 7.14736599655615, 13.2825680960019,
10.5791362373343, 10.8624315112779, 3.18344179431185, 7.49282700058505,
3.78157726350635, 9.96252691997304, 1.69077529836405, 6.67608715745644,
8.37990533734929, 4.20384964117427, 5.22889608012721, 7.8723594660963,
10.730029899683, 8.71664305274389, 4.20979088561725, 3.52386084017096,
7.40856535483994, 12.443352765902, 20.7950248202659, 14.0565344682657,
10.6669381116444, 13.6952498263664, 10.8380984642682, 6.35440732733458,
6.21954204111649, 4.00264648285958, 6.4317520226467, 2.2138115795096,
10.0540395919999, 11.1985829579804, 8.64327410338962, 0.556794049508732,
9.48036917584758, 18.9665686951357, 7.15010318217892, 1.70873116069864,
1.21720094748041, 5.19714843377925, 4.99390365971832, 5.54013921379378,
13.3190512627493, 15.4757059675959, 8.75635769236328, 5.07204433360002,
12.249854335649, 10.8985837736471, 5.39261907053974, 5.873209320872,
10.1689314517544, 16.4360884583216, 21.6810293369496, 14.8433120903617,
5.17306215960223, 8.97856967874759, 15.9031088669131, 7.59291974356731,
3.0192136898866, 10.3889800705301, 8.73409967642436, 9.31468756611007,
13.4058554846685, 8.53438382105245, 14.3729573721071, 18.6696075241301,
8.33988152577507, 7.42672203446524, 1.28062769400986, 8.37801485190093,
10.8397879874016, 8.72028550374256, 0.580257801954223, 4.39712796914426,
7.84989207801702), index = structure(c(62208000, 62294400, 62380800,
62467200, 62553600, 62640000, 62726400, 62812800, 62899200, 62985600,
63072000, 63158400, 63244800, 63331200, 63417600, 63504000, 63590400,
63676800, 63763200, 63849600, 63936000, 64022400, 64108800, 64195200,
64281600, 64368000, 64454400, 64540800, 64627200, 64713600, 64800000,
64886400, 64972800, 65059200, 65145600, 65232000, 65318400, 65404800,
65491200, 65577600, 65664000, 65750400, 65836800, 65923200, 66009600,
66096000, 66182400, 66268800, 66355200, 66441600, 66528000, 66614400,
66700800, 66787200, 66873600, 66960000, 67046400, 67132800, 67219200,
67305600, 67392000, 67478400, 67564800, 67651200, 67737600, 67824000,
67910400, 67996800, 68083200, 68169600, 68256000, 68342400, 68428800,
68515200, 68601600, 68688000, 68774400, 68860800, 68947200, 69033600,
69120000, 69206400, 69292800, 69379200, 69465600, 69552000, 69638400,
69724800, 69811200, 69897600, 69984000, 70070400, 70156800, 70243200,
70329600, 70416000, 70502400, 70588800, 70675200, 70761600, 70848000,
70934400, 71020800, 71107200, 71193600, 71280000, 71366400, 71452800,
71539200, 71625600, 71712000, 71798400, 71884800, 71971200, 72057600,
72144000, 72230400, 72316800, 72403200, 72489600, 72576000, 72662400,
72748800, 72835200, 72921600, 73008000, 73094400, 73180800, 73267200,
73353600, 73440000, 73526400, 73612800, 73699200, 73785600, 73872000,
73958400, 74044800, 74131200, 74217600, 74304000, 74390400, 74476800,
74563200, 74649600, 74736000, 74822400, 74908800, 74995200, 75081600,
75168000, 75254400, 75340800, 75427200, 75513600, 75600000, 75686400,
75772800, 75859200, 75945600, 76032000, 76118400, 76204800, 76291200,
76377600, 76464000, 76550400, 76636800, 76723200, 76809600, 76896000,
76982400, 77068800, 77155200, 77241600, 77328000, 77414400, 77500800,
77587200, 77673600, 77760000, 77846400, 77932800, 78019200, 78105600,
78192000, 78278400, 78364800, 78451200, 78537600, 78624000, 78710400,
78796800, 78883200, 78969600, 79056000, 79142400, 79228800, 79315200,
79401600, 79488000, 79574400, 79660800, 79747200, 79833600, 79920000,
80006400, 80092800, 80179200, 80265600, 80352000, 80438400, 80524800,
80611200, 80697600, 80784000, 80870400, 80956800, 81043200, 81129600,
81216000, 81302400, 81388800, 81475200, 81561600, 81648000, 81734400,
81820800, 81907200, 81993600, 82080000, 82166400, 82252800, 82339200,
82425600, 82512000, 82598400, 82684800, 82771200, 82857600, 82944000,
83030400, 83116800, 83203200, 83289600, 83376000, 83462400, 83548800,
83635200, 83721600, 83808000, 83894400, 83980800, 84067200, 84153600,
84240000, 84326400, 84412800, 84499200, 84585600, 84672000, 84758400,
84844800, 84931200, 85017600, 85104000, 85190400, 85276800, 85363200,
85449600, 85536000, 85622400, 85708800, 85795200, 85881600, 85968000,
86054400, 86140800, 86227200, 86313600, 86400000, 86486400, 86572800,
86659200, 86745600, 86832000, 86918400, 87004800, 87091200, 87177600,
87264000, 87350400, 87436800, 87523200, 87609600, 87696000, 87782400,
87868800, 87955200, 88041600, 88128000, 88214400, 88300800, 88387200,
88473600, 88560000, 88646400, 88732800, 88819200, 88905600, 88992000,
89078400, 89164800, 89251200, 89337600, 89424000, 89510400, 89596800,
89683200, 89769600, 89856000, 89942400, 90028800, 90115200, 90201600,
90288000, 90374400, 90460800, 90547200, 90633600, 90720000, 90806400,
90892800, 90979200, 91065600, 91152000, 91238400, 91324800, 91411200,
91497600, 91584000, 91670400, 91756800, 91843200, 91929600, 92016000,
92102400, 92188800, 92275200, 92361600, 92448000, 92534400, 92620800,
92707200, 92793600, 92880000, 92966400, 93052800, 93139200, 93225600
), cal = "360", months = c(30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30), class = "PCICt", dpy = 360, tzone = "GMT", units = "secs"), class = "zoo")
I am not familiar with 360 day calendar, but the 360-day calender's index seems an epoch-second with the origin of 1970-01-01 in Gregorian Calendar. If this is the case this code will work.
library(data.table)
library(dplyr)
date <- attr(vec360, "index") %>% as.numeric() %>% as.POSIXct(origin="1970-01-01") %>% as.Date()
dt360 <- data.table(vec360, date)
date <- attr(vec365, "index")
dt365 <- data.table(vec365, date)
merged <- merge(dt360, dt365, all = T)
print(merged)
# date vec360 vec365
# 1: 1971-12-22 16.204273 NA
# 2: 1971-12-23 5.544116 NA
# 3: 1971-12-24 8.395240 NA
# 4: 1971-12-25 12.905616 NA
# 5: 1971-12-26 2.610978 NA
# ---
# 372: 1972-12-27 NA 20.525063
# 373: 1972-12-28 NA 24.060095
# 374: 1972-12-29 NA 13.411095
# 375: 1972-12-30 NA 2.920785
# 376: 1972-12-31 NA 9.063221
# get a zoo object back
merged_zoo <- zoo(merged)
Please make sure to check that the epoch second in the index of 360-day vector has the the origin of 1970-01-01.