Re: [R] Problems Structuring My Data
Hello, I am very sad to let you know that my husband Jim died in 18th September. I apologise for not letting you know earlier but I had trouble finding the password for his phone. If you wish to do an obituary please let me know by emailing juelsallybri...@gmail.com, I can send info through. Kind regards, Juel On Wed, 4 Oct 2023, 09:18 Paul Bernal Dear friends, > > Hope you are all doing great. I am working with a dataset which is a subset > of the original one, that has the following columns: FAILDATE, REM_NAME, > and Days_At_Failure. > > I want to structure the data in such a way that I have the unique FAILDATE > in "%Y-%m-%d" format, then a column for each REM_NAME and then the > Days_At_Failure displayed for each REM_NAME and FAILDATE (just as if I was > using a pivot table). > > The structure I want is the following: > FAILDATE REM1 REM2 REM3 REM N > 2000-01-01 # days at failure #days at > failure > 2000-01-02 # days at failure #days at > failure > 2000-01-03 # days at failure #days at > failure > > Here is the dput() of my dataframe: > #I don´t know why R is showing the dates as numbers > #when I do str, it actually shows that FAIL date has type Date > dput(head(failure_subset2, n=1000)) > structure(list(FAILDATE = structure(c(17597, 17597, 17347, 17334, > 17148, 17168, 17299, 17402, 17406, 17347, 17505, 17449, 17352, > 17931, 17424, 17439, 17406, 17292, 17390, 17373, 17259, 17561, > 17563, 17550, 17723, 17814, 17564, 17299, 17307, 17296, 17483, > 17644, 17394, 17360, 17850, 17744, 17719, 17712, 17710, 18048, > 18069, 17876, 17506, 17821, 18041, 17586, 18069, 18069, 18048, > 17899, 17899, 17759, 17732, 17822, 17771, 17821, 17837, 17824, > 17469, 17483, 17582, 17613, 18016, 18036, 18030, 17862, 17871, > 17899, 17651, 17684, 17844, 17632, 17784, 17855, 17764, 17915, > 18245, 18260, 18166, 18295, 18094, 18062, 18083, 18223, 18237, > 18197, 18284, 18289, 18218, 18218, 18298, 18297, 18299, 17910, > 18089, 18304, 18141, 18272, 18387, 18183, 18184, 18422, 18422, > 18422, 18038, 17988, 18413, 17836, 18328, 18230, 18011, 18011, > 17991, 18041, 18041, 18070, 18432, 18031, 18165, 18345, 18386, > 17899, 18374, 18427, 18098, 18416, 18397, 18458, 18126, 18126, > 18123, 18286, 17827, 18069, 18081, 18505, 18508, 18086, 18468, > 18482, 18107, 18146, 18371, 18368, 18186, 18270, 17772, 18054, > 17959, 18106, 18148, 18380, 18398, 17921, 18265, 18273, 18030, > 18473, 18166, 18006, 18006, 18006, 18000, 17938, 18155, 18175, > 18047, 18503, 18042, 18072, 17964, 18223, 17850, 17871, 18071, > 18174, 18154, 18153, 18344, 18384, 18512, 18112, 18131, 18085, > 18094, 18096, 18100, 18477, 17967, 17752, 17964, 18491, 18124, > 18115, 18166, 17912, 18489, 18087, 18130, 18170, 18169, 18175, > 18177, 18226, 18376, 18374, 18217, 18226, 18135, 18136, 17942, > 18099, 18031, 18032, 18107, 18041, 18062, 18078, 18087, 18249, > 18081, 18231, 18195, 18192, 18213, 18209, 18156, 18157, 18157, > 18158, 18159, 18053, 18221, 18185, 18311, 18239, 18258, 18390, > 18390, 17997, 18197, 18095, 18145, 18101, 18194, 18260, 18260, > 18202, 18447, 18450, 18088, 18249, 18206, 18290, 17995, 18270, > 18282, 18251, 18157, 18094, 18437, 18299, 18333, 18035, 18146, > 18010, 18395, 18204, 18259, 18311, 18335, 18444, 18444, 18453, > 18453, 18192, 18098, 17969, 17680, 18147, 18147, 17977, 17996, > 18001, 18399, 18432, 18354, 18147, 17912, 17995, 17995, 18221, > 18428, 18447, 18452, 18264, 18321, 18334, 18386, 18156, 18371, > 18345, 18156, 18164, 18029, 18433, 17602, 17931, 18290, 18339, > 18424, 18052, 18052, 18166, 18540, 18783, 18166, 18607, 18606, > 18606, 18594, 18592, 18805, 18648, 18768, 18887, 1, 18648, > 18630, 18812, 18812, 18845, 18932, 18418, 18950, 18166, 18702, > 18684, 18812, 18589, 18597, 18611, 18648, 18577, 19024, 19041, > 19043, 18768, 19216, 18787, 19159, 18529, 18589, 18646, 18166, > 18571, 18637, 18624, 18716, 18166, 18568, 18527, 18535, 18542, > 18494, 18846, 18166, 18877, 18548, 18659, 18839, 18905, 18632, > 18804, 18648, 18892, 18921, 18718, 18805, 18805, 18561, 18682, > 18943, 18949, 18542, 18927, 18409, 19047, 19059, 18524, 18941, > 18941, 18941, 18648, 19044, 18758, 19034, 18609, 18788, 18812, > 18676, 19194, 18740, 18812, 18842, 18659, 19042, 18230, 19036, > 19144, 19032, 18542, 19097, 18564, 18166, 18552, 18557, 18467, > 19002, 19174, 18624, 18828, 18542, 18542, 18686, 18628, 18702, > 19227, 19239, 19264, 17597, 17470, 17401, 17344, 17562, 17578, > 17476, 17539, 17348, 17326, 17420, 17423, 17427, 17347, 17359, > 17372, 17385, 17365, 17365, 17598, 17977, 17977, 17736, 17684, > 17612, 17792, 17220, 17310, 17452, 17641, 17813, 17407, 17712, > 17697, 17752, 17694, 17724, 17862, 17865, 17633, 18048, 17815, > 17911, 17753, 17818, 17784, 17619, 17697, 17381, 17641, 17449, > 17456, 17555, 17564, 17574, 17793, 17889, 17869, 17885, 17890, > 17903, 17912, 17809, 17891, 17846, 17916, 18019, 18234, 18180, > 18181, 18292,
Re: [R] Problems Structuring My Data
I'll make an attempt to answer your question, but the results seems extremely wasteful, as there appears to be only one REMNAME for each FAILDATE. This means for my "solution", almost all of the entries are empty (NULL, actually). So I assume I must misunderstand your specification, but maybe showing you my misunderstanding will help you and/or others to clarify or it. Anyway, calling the data frame you provided, d, my "solution" is simply (I changed your variable names to fdate, name, and fdays to save typing): w <- with(d, tapply(fdays, list(factor(fdate), name), I)) ## that's an I = "eye" at the end not an "ell" w is a *matrix* of the fdays, with the rownames of the matrix your dates, and the colnames your remnames. The dimension of w is 640 x 43. As I said, most of the entries are NULL. If this *is* perchance what you want, then I suggest you stay with your original data frame and rethink how to work with it more efficiently. You should *not* be guided by imitating what one does in Excel. However, as is more likely, I've just misunderstood what you want, so a bit of clarification might get you the answer you seek. Bon chance. Cheers, Bert On Tue, Oct 3, 2023 at 4:25 PM Bert Gunter wrote: > > I won't attempt to answer your post here, but: > > #I don´t know why R is showing the dates as numbers > > Please read the Help files! > You say FAILDATE has "type" = S3 class, "Date". > The first thing ?Dates tells you in the "Details" is: > > "Dates are represented as the number of days since 1970-01-01, with > negative values for earlier dates. They are always printed following > the rules of the current Gregorian calendar, even though that calendar > was not in use long ago (it was adopted in 1752 in Great Britain and > its colonies)." > > That answers your question without ever needing to post here. > > Cheers, > Bert > > > > On Tue, Oct 3, 2023 at 3:18 PM Paul Bernal wrote: > > > > Dear friends, > > > > Hope you are all doing great. I am working with a dataset which is a subset > > of the original one, that has the following columns: FAILDATE, REM_NAME, > > and Days_At_Failure. > > > > I want to structure the data in such a way that I have the unique FAILDATE > > in "%Y-%m-%d" format, then a column for each REM_NAME and then the > > Days_At_Failure displayed for each REM_NAME and FAILDATE (just as if I was > > using a pivot table). > > > > The structure I want is the following: > > FAILDATE REM1 REM2 REM3 REM N > > 2000-01-01 # days at failure #days at > > failure > > 2000-01-02 # days at failure #days at > > failure > > 2000-01-03 # days at failure #days at > > failure > > > > Here is the dput() of my dataframe: > > #I don´t know why R is showing the dates as numbers > > #when I do str, it actually shows that FAIL date has type Date > > dput(head(failure_subset2, n=1000)) > > structure(list(FAILDATE = structure(c(17597, 17597, 17347, 17334, > > 17148, 17168, 17299, 17402, 17406, 17347, 17505, 17449, 17352, > > 17931, 17424, 17439, 17406, 17292, 17390, 17373, 17259, 17561, > > 17563, 17550, 17723, 17814, 17564, 17299, 17307, 17296, 17483, > > 17644, 17394, 17360, 17850, 17744, 17719, 17712, 17710, 18048, > > 18069, 17876, 17506, 17821, 18041, 17586, 18069, 18069, 18048, > > 17899, 17899, 17759, 17732, 17822, 17771, 17821, 17837, 17824, > > 17469, 17483, 17582, 17613, 18016, 18036, 18030, 17862, 17871, > > 17899, 17651, 17684, 17844, 17632, 17784, 17855, 17764, 17915, > > 18245, 18260, 18166, 18295, 18094, 18062, 18083, 18223, 18237, > > 18197, 18284, 18289, 18218, 18218, 18298, 18297, 18299, 17910, > > 18089, 18304, 18141, 18272, 18387, 18183, 18184, 18422, 18422, > > 18422, 18038, 17988, 18413, 17836, 18328, 18230, 18011, 18011, > > 17991, 18041, 18041, 18070, 18432, 18031, 18165, 18345, 18386, > > 17899, 18374, 18427, 18098, 18416, 18397, 18458, 18126, 18126, > > 18123, 18286, 17827, 18069, 18081, 18505, 18508, 18086, 18468, > > 18482, 18107, 18146, 18371, 18368, 18186, 18270, 17772, 18054, > > 17959, 18106, 18148, 18380, 18398, 17921, 18265, 18273, 18030, > > 18473, 18166, 18006, 18006, 18006, 18000, 17938, 18155, 18175, > > 18047, 18503, 18042, 18072, 17964, 18223, 17850, 17871, 18071, > > 18174, 18154, 18153, 18344, 18384, 18512, 18112, 18131, 18085, > > 18094, 18096, 18100, 18477, 17967, 17752, 17964, 18491, 18124, > > 18115, 18166, 17912, 18489, 18087, 18130, 18170, 18169, 18175, > > 18177, 18226, 18376, 18374, 18217, 18226, 18135, 18136, 17942, > > 18099, 18031, 18032, 18107, 18041, 18062, 18078, 18087, 18249, > > 18081, 18231, 18195, 18192, 18213, 18209, 18156, 18157, 18157, > > 18158, 18159, 18053, 18221, 18185, 18311, 18239, 18258, 18390, > > 18390, 17997, 18197, 18095, 18145, 18101, 18194, 18260, 18260, > > 18202, 18447, 18450, 18088, 18249, 18206, 18290, 17995, 18270, > > 18282, 18251, 18157, 18094, 18437, 18299, 18333, 18035, 18146, > > 18010, 18395, 18204,
Re: [R] Problems Structuring My Data
I won't attempt to answer your post here, but: #I don´t know why R is showing the dates as numbers Please read the Help files! You say FAILDATE has "type" = S3 class, "Date". The first thing ?Dates tells you in the "Details" is: "Dates are represented as the number of days since 1970-01-01, with negative values for earlier dates. They are always printed following the rules of the current Gregorian calendar, even though that calendar was not in use long ago (it was adopted in 1752 in Great Britain and its colonies)." That answers your question without ever needing to post here. Cheers, Bert On Tue, Oct 3, 2023 at 3:18 PM Paul Bernal wrote: > > Dear friends, > > Hope you are all doing great. I am working with a dataset which is a subset > of the original one, that has the following columns: FAILDATE, REM_NAME, > and Days_At_Failure. > > I want to structure the data in such a way that I have the unique FAILDATE > in "%Y-%m-%d" format, then a column for each REM_NAME and then the > Days_At_Failure displayed for each REM_NAME and FAILDATE (just as if I was > using a pivot table). > > The structure I want is the following: > FAILDATE REM1 REM2 REM3 REM N > 2000-01-01 # days at failure #days at > failure > 2000-01-02 # days at failure #days at > failure > 2000-01-03 # days at failure #days at > failure > > Here is the dput() of my dataframe: > #I don´t know why R is showing the dates as numbers > #when I do str, it actually shows that FAIL date has type Date > dput(head(failure_subset2, n=1000)) > structure(list(FAILDATE = structure(c(17597, 17597, 17347, 17334, > 17148, 17168, 17299, 17402, 17406, 17347, 17505, 17449, 17352, > 17931, 17424, 17439, 17406, 17292, 17390, 17373, 17259, 17561, > 17563, 17550, 17723, 17814, 17564, 17299, 17307, 17296, 17483, > 17644, 17394, 17360, 17850, 17744, 17719, 17712, 17710, 18048, > 18069, 17876, 17506, 17821, 18041, 17586, 18069, 18069, 18048, > 17899, 17899, 17759, 17732, 17822, 17771, 17821, 17837, 17824, > 17469, 17483, 17582, 17613, 18016, 18036, 18030, 17862, 17871, > 17899, 17651, 17684, 17844, 17632, 17784, 17855, 17764, 17915, > 18245, 18260, 18166, 18295, 18094, 18062, 18083, 18223, 18237, > 18197, 18284, 18289, 18218, 18218, 18298, 18297, 18299, 17910, > 18089, 18304, 18141, 18272, 18387, 18183, 18184, 18422, 18422, > 18422, 18038, 17988, 18413, 17836, 18328, 18230, 18011, 18011, > 17991, 18041, 18041, 18070, 18432, 18031, 18165, 18345, 18386, > 17899, 18374, 18427, 18098, 18416, 18397, 18458, 18126, 18126, > 18123, 18286, 17827, 18069, 18081, 18505, 18508, 18086, 18468, > 18482, 18107, 18146, 18371, 18368, 18186, 18270, 17772, 18054, > 17959, 18106, 18148, 18380, 18398, 17921, 18265, 18273, 18030, > 18473, 18166, 18006, 18006, 18006, 18000, 17938, 18155, 18175, > 18047, 18503, 18042, 18072, 17964, 18223, 17850, 17871, 18071, > 18174, 18154, 18153, 18344, 18384, 18512, 18112, 18131, 18085, > 18094, 18096, 18100, 18477, 17967, 17752, 17964, 18491, 18124, > 18115, 18166, 17912, 18489, 18087, 18130, 18170, 18169, 18175, > 18177, 18226, 18376, 18374, 18217, 18226, 18135, 18136, 17942, > 18099, 18031, 18032, 18107, 18041, 18062, 18078, 18087, 18249, > 18081, 18231, 18195, 18192, 18213, 18209, 18156, 18157, 18157, > 18158, 18159, 18053, 18221, 18185, 18311, 18239, 18258, 18390, > 18390, 17997, 18197, 18095, 18145, 18101, 18194, 18260, 18260, > 18202, 18447, 18450, 18088, 18249, 18206, 18290, 17995, 18270, > 18282, 18251, 18157, 18094, 18437, 18299, 18333, 18035, 18146, > 18010, 18395, 18204, 18259, 18311, 18335, 18444, 18444, 18453, > 18453, 18192, 18098, 17969, 17680, 18147, 18147, 17977, 17996, > 18001, 18399, 18432, 18354, 18147, 17912, 17995, 17995, 18221, > 18428, 18447, 18452, 18264, 18321, 18334, 18386, 18156, 18371, > 18345, 18156, 18164, 18029, 18433, 17602, 17931, 18290, 18339, > 18424, 18052, 18052, 18166, 18540, 18783, 18166, 18607, 18606, > 18606, 18594, 18592, 18805, 18648, 18768, 18887, 1, 18648, > 18630, 18812, 18812, 18845, 18932, 18418, 18950, 18166, 18702, > 18684, 18812, 18589, 18597, 18611, 18648, 18577, 19024, 19041, > 19043, 18768, 19216, 18787, 19159, 18529, 18589, 18646, 18166, > 18571, 18637, 18624, 18716, 18166, 18568, 18527, 18535, 18542, > 18494, 18846, 18166, 18877, 18548, 18659, 18839, 18905, 18632, > 18804, 18648, 18892, 18921, 18718, 18805, 18805, 18561, 18682, > 18943, 18949, 18542, 18927, 18409, 19047, 19059, 18524, 18941, > 18941, 18941, 18648, 19044, 18758, 19034, 18609, 18788, 18812, > 18676, 19194, 18740, 18812, 18842, 18659, 19042, 18230, 19036, > 19144, 19032, 18542, 19097, 18564, 18166, 18552, 18557, 18467, > 19002, 19174, 18624, 18828, 18542, 18542, 18686, 18628, 18702, > 19227, 19239, 19264, 17597, 17470, 17401, 17344, 17562, 17578, > 17476, 17539, 17348, 17326, 17420, 17423, 17427, 17347, 17359, > 17372, 17385, 17365, 17365, 17598, 17977, 17977, 17736, 17684, > 17612, 17792, 17220, 17310,
[R] Problems Structuring My Data
Dear friends, Hope you are all doing great. I am working with a dataset which is a subset of the original one, that has the following columns: FAILDATE, REM_NAME, and Days_At_Failure. I want to structure the data in such a way that I have the unique FAILDATE in "%Y-%m-%d" format, then a column for each REM_NAME and then the Days_At_Failure displayed for each REM_NAME and FAILDATE (just as if I was using a pivot table). The structure I want is the following: FAILDATE REM1 REM2 REM3 REM N 2000-01-01 # days at failure #days at failure 2000-01-02 # days at failure #days at failure 2000-01-03 # days at failure #days at failure Here is the dput() of my dataframe: #I don´t know why R is showing the dates as numbers #when I do str, it actually shows that FAIL date has type Date dput(head(failure_subset2, n=1000)) structure(list(FAILDATE = structure(c(17597, 17597, 17347, 17334, 17148, 17168, 17299, 17402, 17406, 17347, 17505, 17449, 17352, 17931, 17424, 17439, 17406, 17292, 17390, 17373, 17259, 17561, 17563, 17550, 17723, 17814, 17564, 17299, 17307, 17296, 17483, 17644, 17394, 17360, 17850, 17744, 17719, 17712, 17710, 18048, 18069, 17876, 17506, 17821, 18041, 17586, 18069, 18069, 18048, 17899, 17899, 17759, 17732, 17822, 17771, 17821, 17837, 17824, 17469, 17483, 17582, 17613, 18016, 18036, 18030, 17862, 17871, 17899, 17651, 17684, 17844, 17632, 17784, 17855, 17764, 17915, 18245, 18260, 18166, 18295, 18094, 18062, 18083, 18223, 18237, 18197, 18284, 18289, 18218, 18218, 18298, 18297, 18299, 17910, 18089, 18304, 18141, 18272, 18387, 18183, 18184, 18422, 18422, 18422, 18038, 17988, 18413, 17836, 18328, 18230, 18011, 18011, 17991, 18041, 18041, 18070, 18432, 18031, 18165, 18345, 18386, 17899, 18374, 18427, 18098, 18416, 18397, 18458, 18126, 18126, 18123, 18286, 17827, 18069, 18081, 18505, 18508, 18086, 18468, 18482, 18107, 18146, 18371, 18368, 18186, 18270, 17772, 18054, 17959, 18106, 18148, 18380, 18398, 17921, 18265, 18273, 18030, 18473, 18166, 18006, 18006, 18006, 18000, 17938, 18155, 18175, 18047, 18503, 18042, 18072, 17964, 18223, 17850, 17871, 18071, 18174, 18154, 18153, 18344, 18384, 18512, 18112, 18131, 18085, 18094, 18096, 18100, 18477, 17967, 17752, 17964, 18491, 18124, 18115, 18166, 17912, 18489, 18087, 18130, 18170, 18169, 18175, 18177, 18226, 18376, 18374, 18217, 18226, 18135, 18136, 17942, 18099, 18031, 18032, 18107, 18041, 18062, 18078, 18087, 18249, 18081, 18231, 18195, 18192, 18213, 18209, 18156, 18157, 18157, 18158, 18159, 18053, 18221, 18185, 18311, 18239, 18258, 18390, 18390, 17997, 18197, 18095, 18145, 18101, 18194, 18260, 18260, 18202, 18447, 18450, 18088, 18249, 18206, 18290, 17995, 18270, 18282, 18251, 18157, 18094, 18437, 18299, 18333, 18035, 18146, 18010, 18395, 18204, 18259, 18311, 18335, 18444, 18444, 18453, 18453, 18192, 18098, 17969, 17680, 18147, 18147, 17977, 17996, 18001, 18399, 18432, 18354, 18147, 17912, 17995, 17995, 18221, 18428, 18447, 18452, 18264, 18321, 18334, 18386, 18156, 18371, 18345, 18156, 18164, 18029, 18433, 17602, 17931, 18290, 18339, 18424, 18052, 18052, 18166, 18540, 18783, 18166, 18607, 18606, 18606, 18594, 18592, 18805, 18648, 18768, 18887, 1, 18648, 18630, 18812, 18812, 18845, 18932, 18418, 18950, 18166, 18702, 18684, 18812, 18589, 18597, 18611, 18648, 18577, 19024, 19041, 19043, 18768, 19216, 18787, 19159, 18529, 18589, 18646, 18166, 18571, 18637, 18624, 18716, 18166, 18568, 18527, 18535, 18542, 18494, 18846, 18166, 18877, 18548, 18659, 18839, 18905, 18632, 18804, 18648, 18892, 18921, 18718, 18805, 18805, 18561, 18682, 18943, 18949, 18542, 18927, 18409, 19047, 19059, 18524, 18941, 18941, 18941, 18648, 19044, 18758, 19034, 18609, 18788, 18812, 18676, 19194, 18740, 18812, 18842, 18659, 19042, 18230, 19036, 19144, 19032, 18542, 19097, 18564, 18166, 18552, 18557, 18467, 19002, 19174, 18624, 18828, 18542, 18542, 18686, 18628, 18702, 19227, 19239, 19264, 17597, 17470, 17401, 17344, 17562, 17578, 17476, 17539, 17348, 17326, 17420, 17423, 17427, 17347, 17359, 17372, 17385, 17365, 17365, 17598, 17977, 17977, 17736, 17684, 17612, 17792, 17220, 17310, 17452, 17641, 17813, 17407, 17712, 17697, 17752, 17694, 17724, 17862, 17865, 17633, 18048, 17815, 17911, 17753, 17818, 17784, 17619, 17697, 17381, 17641, 17449, 17456, 17555, 17564, 17574, 17793, 17889, 17869, 17885, 17890, 17903, 17912, 17809, 17891, 17846, 17916, 18019, 18234, 18180, 18181, 18292, 18140, 18036, 18289, 18278, 18298, 18297, 18295, 18319, 18313, 17936, 17939, 18109, 18340, 18166, 18206, 18204, 17904, 17998, 18269, 18165, 18120, 18349, 18368, 18416, 18416, 18025, 18322, 17989, 17830, 17845, 17869, 18065, 18328, 18324, 17944, 17920, 18433, 17962, 18169, 18170, 18171, 18340, 18393, 18070, 18083, 18087, 18108, 18116, 18142, 18386, 18425, 18464, 18498, 18400, 17931, 18459, 18126, 18124, 18310, 18228, 17828, 17851, 18143, 18028, 18425, 18416, 18482, 18482, 18396, 18428, 18414, 18441,