R-导入带有日期列的xlsx文件 [英] R - Importing xlsx file with date column
本文介绍了R-导入带有日期列的xlsx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试读取Excel文件时,它总是弄乱日期/时间。
When I try to read in an excel file it always messes with the date/time.
library(openxlsx)
download.file("http://ec.europa.eu/economy_finance/db_indicators/surveys/documents/series/nace2_ecfin_1801/services_subsectors_sa_nace2.zip", destfile="services_subsectors_sa_nace2.zip")
unzip("services_subsectors_sa_nace2.zip")
bcs<-read.xlsx("services_subsectors_sa_m_nace2.xlsx", colNames=TRUE, sheet="73")
第1列(原始数据集中未提供名称)将为日期/时间列。默认情况下,该列在输入R时会被赋予名称73。
Column 1 (no name given in the original dataset) would be the date/time column. By default this colum gets given the name 73 when it enters R.
我尝试过
as.POSIXct(bcs$73, format="%d/%m/%Y", tz="CET")
我们非常感谢您的帮助。谢谢:)
Any help is much appreciated. Thank you :)
推荐答案
您可以使用 janitor
包,尤其是功能 excel_numeric_to_date
。
You can use the janitor
package, especially the function excel_numeric_to_date
.
另一个选项将使用软件包 readxl
来读取您的Excel文件,该文件会自动转换datetime中的日期列:
Another option would be to use the package readxl
to read your excel file which converts automatically date columns in datetime :
library(readxl)
read_excel("services_subsectors_sa_m_nace2.xlsx", sheet="73")
这篇关于R-导入带有日期列的xlsx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文