0

I am new to R and I get this problem when I am learning by myself. If anyone can help me with this I'll be grateful for that. Here's the problem I have: I can execute the code below on a R online editor successfully, but I cannot run it on my own R studio. When I run the strptime() code on my R studio I can only get [1] NA for y instead of getting the right format. The same case also happens when I use as.POSIXlt(). Btw my R version is 3.3.2, which is the latest one, and the online editor is 3.3.1 version. I am not sure whether it's a problem about version. Please tell me what should I do to solve this problem or is there any other substitution for this code. Thanks.

x <- "Dec 31 2016 12:34"
y <- strptime(x, "%B %d %Y %H:%M")
x
y
  • It works in R 3.3.2 for me – akrun Mar 05 '17 at 11:28
  • Most likely because of your locale: [strptime, as.POSIXct and as.Date return unexpected NA](http://stackoverflow.com/questions/13726894/strptime-as-posixct-and-as-date-return-unexpected-na) – Henrik Mar 05 '17 at 11:29
  • @Henrik You are right. It does relate to my locale. Thanks a lot!! BTW so do I need to change my locale every time to run such code in every script that has something to do with it? – znnnVito Mar 05 '17 at 11:55
  • 1
    @znnnVito If you always use dates of a particular locale, you may set locale 'automatically' at the startup of an R session, by adding e.g. `Sys.setlocale("LC_TIME", "C")` to the startup profile file of R. The default location of this file is "`R_HOME`/etc/Rprofile.site" (see `?Startup`). – Henrik Mar 05 '17 at 12:15
  • @Henrik Thanks very much I'm fully aware of it now – znnnVito Mar 05 '17 at 13:28

0 Answers0