R:日期格式转换

lmc*_*ane -1 r date

我有以下日期格式的Twitter数据:

date <- "Wed Jan 07 20:57:02 +0000 2015"
Run Code Online (Sandbox Code Playgroud)

有谁知道这是一个标准的日期格式?任何可以将它转换为mdy的包?

Jot*_*ota 6

在基数R中,您可以使用formatstrptime. strptime将字符表示转换为POSIXlt,format并将生成的POSIXlt类对象转换为所需格式的字符表示形式.有关?strptime详细信息,请参阅 还有一个帮助页面DateTimeClasses.

对于这种情况,您可以使用:

format(
  strptime(date, format="%a %b %d %T %z %Y"),
  "%m-%d-%Y"
  )
#[1] "01-07-2015"
Run Code Online (Sandbox Code Playgroud)

格式为:

abbreviated day of the week                 %a
abbreviated month                           %b
day of month as decimal number              %d
hours:minutes:seconds                       %T
signed offset from UTC in hours and minutes %z
year with century                           %Y
Run Code Online (Sandbox Code Playgroud)