r - 在 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")
你能帮忙吗?谢谢。
解决方案
你可以试试 :
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
推荐阅读
- r - knitr在渲染时没有正确采购项目.Rprofile
- swift - iOS - 如何在没有第三方框架的情况下在 Swift 中创建自定义动画横幅
- python-3.x - 如何通过beautifulsoup4将抓取的数据上传到csv文件
- video - 使用 FFmpeg 添加 2 个带有 scale2ref 40% 视频宽度和超时的水印
- node.js - 既然 appcfg 不见了,就从 app_engine 下载源代码?
- karate - 空手道 - 仅对引用的对象进行模式验证,默认情况下忽略未引用的对象
- android - DrawerLayout 内的 constraintLayout 内的 RecyclerView 不会滚动
- javascript - 是否可以在没有所有参数的情况下调用/等待异步函数?
- react-admin - 如果我想在过滤器和列表之间添加一些信息文本怎么办?
- assembly - 调用 printf 在使用 gcc 编译的程序集中产生分段错误、核心转储错误