|
ElMaestro ★★★ Denmark, 2025-11-10 13:26 (205 d 11:08 ago) (edited on 2025-11-10 13:42) Posting: # 24483 Views: 2,916 |
|
|
Hi all, can someone try this:
Date.str=paste0("01/", month.abb[c(1:12)], "/2024")The code creates some dates as string for first day of all months and then tries to interpret the strings as dates. I am getting an NA for September. Oddly, if I abbreviate September as "Sept" rather then "Sep" as.Date("01/Sept/2024",format='%d/%b/%Y')then it works, in spite of the fact that month.abb[9] is Sep and not Sept on my system.![]() Does it behave the same way on your system? Mine is Win11 installed last week along with a fresh R install. Add.: Oh dear, is %b locale-dependent? Shoot me, please. Put me out of my misery. This is not good.— Pass or fail! ElMaestro |
|
mittyri ★★ Russia, 2025-11-10 21:38 (205 d 02:56 ago) @ ElMaestro Posting: # 24485 Views: 2,553 |
|
|
Hi ElMaestro, On my system
Date.str=paste0("01/", month.abb[c(1:12)], "/2024")but
month.abb[9]
[1] "Sep"❝ Add.: Oh dear, is %b locale-dependent? Shoot me, please. Put me out of my misery. This is not good. You nailed it down. Yes, %b (and thus as.Date()) is indeed locale-dependent in R, as it relies on the C strptime() function, which pulls month abbreviations from your system's locale settings.On your setup (en_GB locale?), the system abbreviated name for September is "Sept" (a four-letter). So when you feed "01/Sep/2024" to as.Date(format = '%d/%b/%Y'), it fails with NA because the parser doesn't recognize "Sep" as matching the expected "Sept"However, month.abb (and month.name) are hardcoded constants in R base package, always using the three-letter forms regardless of your locale. This creates the exact mismatch you're seeing.I know it is painful, locales are driving me crazy everytime (so I stick to US years ago) — Kind regards, Mittyri |
|
Helmut ★★★ ![]() Vienna, Austria, 2025-11-11 10:37 (204 d 13:57 ago) @ ElMaestro Posting: # 24487 Views: 2,561 |
|
|
Hi ElMaestro, Mittyri explained it already. With my locale (German_Austria) it is even worse… Date.str Date.I… because the constants month.name and month.abb give the English month names and their three letter abbreviations irrespective of the locale.month.nameTherefore, with your code I get NAs for January, March, May, and October because they do not match my locale: Jänner (Jän), März (Mär), Mai (Mai), Oktober (Okt). With German_Germany January would match: Januar (Jan). Does that help?
I don’t know what you want to achieve but in my codes I only use the ISO-date YYYY-MM-DD (in R: " %Y-%m-%d" or simply "%F") without caring about the names of months.
Month names and abbreviations can be interesting (check esp. the French ones):
— Dif-tor heh smusma 🖖🏼 Довге життя Україна! ![]() Helmut Schütz ![]() The quality of responses received is directly proportional to the quality of the question asked. 🚮 Science Quotes |
|
ElMaestro ★★★ Denmark, 2025-11-13 06:20 (202 d 18:14 ago) @ Helmut Posting: # 24495 Views: 2,389 |
|
|
Hi Hötzi, hi all, ❝ I don’t know what you want to achieve but (...) Well, some degree of sanity is part of my general goals. But obviously, in that case I should not have gone into bioequivalence to start with. Some days ago I received a csv file with dates like "03/Apr/2024" for ~5000 data points or so (cancer PD marker level, subjects, visits, timings, and a Brazilian other columns). There are repeats in the data and I need to extract the latest data for of such repeats as these will be the ones used for stats. So, I have to sort the data by subject and by date. Since %b as Mittyri says uses a deep C call which queries the locale, there is no easy way of doing this. The solution I see is to translate every month abbrev in the data to the corresponding month abbrev of my locale and only then can it be sorted. Same thing if I convert the month abbrev to integer. Both options are equally viable. Clumsy, but I will get there. ![]() I do not in any way have influence on the way the data file is generated or which date format the other party decide to use before sending it to me. — Pass or fail! ElMaestro |
|
Helmut ★★★ ![]() Vienna, Austria, 2025-11-13 13:45 (202 d 10:48 ago) @ ElMaestro Posting: # 24496 Views: 2,374 |
|
|
Hi ElMaestro, ❝ Well, some degree of sanity is part of my general goals. But obviously, in that case I should not have gone into bioequivalence to start with. ![]() ❝ […] a csv file with dates like "03/Apr/2024" … ❝ The solution I see is to translate every month abbrev in the data to the corresponding month abbrev of my locale and only then can it be sorted. Same thing if I convert the month abbrev to integer. Both options are equally viable. Clumsy, but I will get there. Do you import the data with read.csv()? I would suggest read.table() instead. Then you can makes sure the ugly column is read as characters and it’s easy to split it into day, month, year, and convert to an ISO-date.months <- function(lang = "en") {— Dif-tor heh smusma 🖖🏼 Довге життя Україна! ![]() Helmut Schütz ![]() The quality of responses received is directly proportional to the quality of the question asked. 🚮 Science Quotes |
|
ElMaestro ★★★ Denmark, 2025-11-14 17:34 (201 d 07:00 ago) @ Helmut Posting: # 24497 Views: 2,315 |
|
|
Hi Hötzi ❝ Do you import the data with Once I understand the underlying issue I can usually solve it, that part tends to be no problem. Yes I use both read.csv or read.table when importing tables but probably not in the smartest fashion, however that is otherwise defined. It is a little beyond me that if I want abbreviated months then they are from a single set locale which may differs from the users. And when we work with the abbreviations through %b then the corresponding abbreviations get locale-dependent. The logic escapes me and confuses me. But once the dust settles in the back of my head, I can work out a solution, clumsy as it may be, with just a modest amount of effort. ![]() — Pass or fail! ElMaestro |
|
Ohlbe ★★★ France, 2025-11-12 16:13 (203 d 08:21 ago) @ ElMaestro Posting: # 24493 Views: 2,459 |
|
|
Dear ElMaestro, As expected from Helmut's post, it is worse with the French locale "French_France.utf8": Date.str Date.I— Regards Ohlbe |
|
ElMaestro ★★★ Denmark, 2025-11-14 17:38 (201 d 06:56 ago) @ Ohlbe Posting: # 24498 Views: 2,331 |
|
|
Hi Ohlbe and all, thanks for all input. In short, the answers to my questions are 1. "yes" (or "yes, principally") 2. "yes" ![]() — Pass or fail! ElMaestro |


![[image]](https://static.bebac.at/pics/Blue_and_yellow_ribbon_UA.png)
![[image]](https://static.bebac.at/img/CC by.png)


