R - Importing xlsx file with date column

我的梦境 提交于 2019-12-08 11:44:28

问题


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")

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.

I tried

as.POSIXct(bcs$73, format="%d/%m/%Y", tz="CET")

Any help is much appreciated. Thank you :)


回答1:


You can use the janitor package, especially the function excel_numeric_to_date.

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")


来源:https://stackoverflow.com/questions/48804353/r-importing-xlsx-file-with-date-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!