首页 > 解决方案 > 在 R 中导入 excel 文件时出现日期格式问题

问题描述

我正在尝试在 rpivottable 的月份列中获取Jan 20日期June 20。但它总是以 yyyy-mm-dd 格式显示,例如2020-01-01. 我的代码如下:

    library(readxl)
    library(rpivotTable) 
    myexcel <- read_excel("claimH1data_date.xlsx")
    x <- myexcel$Month
    as.Date(x, format, tryFormats = c("%m-%Y"),tz = "UTC",
    optional = TRUE)
    format(x, format="%B %Y")
    View(x)
    rpivotTable(myexcel, rows = "Month",cols="Action", vals = "Freq", 
    aggregatorName = "Count", rendererName = "Table")

你能帮忙吗?谢谢。

标签: r

解决方案


你可以试试 :

library(readxl)
#Read the data
myexcel <- read_excel("claimH1data_date.xlsx")
#Sort the data based on date
myexcel <- myexcel[order(myexcel$Month), ]
#Apply the format
myexcel$Month <- format(myexcel$Month, format="%B %Y")
myexcel

推荐阅读