-1

I am wondering if there is an effective function or package in R that returns the time zone of the state that is fed into it. For example, if you fed the function "CA", it would return with "PST" or "Pacific".

>function("CA")
>"PST"

Thanks

  • 1
    You should rephrase your question into "how can I get the timezone from...", and you may have answers about external packages or not, questions that ask for a package are closed. – moodymudskipper Jul 30 '18 at 13:59
  • 2
    [Some states have more than one time zone](https://www.thoughtco.com/states-split-into-two-time-zones-4072169). – MrFlick Jul 30 '18 at 14:01
  • Dup is asking about PHP, but the question is the same, and so is the answer. No - it cannot be done because several states have more than one time zone. You will need [latitude and longitude coordinates](https://stackoverflow.com/questions/16086962/how-to-get-a-time-zone-from-a-location-using-latitude-and-longitude-coordinates) to resolve a time zone. – Matt Johnson-Pint Jul 31 '18 at 17:10

1 Answers1

0

You could use some code like this, if you have a list of what results you want for each state (taking account of MrFlick's commment).

library(dplyr)
case_when(
  x %in% c("1", "2", "3") ~ "Central Time", 
  x %in% c("4", "5", "6") ~ "Pacific Time", 
)

Here, 1,2,3 would be the names of states and you can add time zones as necessary.

Luke Hayden
  • 692
  • 4
  • 8