R - 导入带有日期列的 xlsx 文件
R - Importing xlsx file with date column
当我尝试读取 excel 文件时,它总是与 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 列(原始数据集中未给出名称)将是 date/time 列。默认情况下,此列在进入 R 时会获得名称 73。
我试过了
as.POSIXct(bcs, format="%d/%m/%Y", tz="CET")
非常感谢任何帮助。谢谢:)
您可以使用 janitor
package, especially the function excel_numeric_to_date
.
另一种选择是使用包 readxl
读取您的 excel 文件,该文件会自动转换日期时间中的日期列:
library(readxl)
read_excel("services_subsectors_sa_m_nace2.xlsx", sheet="73")
当我尝试读取 excel 文件时,它总是与 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 列(原始数据集中未给出名称)将是 date/time 列。默认情况下,此列在进入 R 时会获得名称 73。
我试过了
as.POSIXct(bcs, format="%d/%m/%Y", tz="CET")
非常感谢任何帮助。谢谢:)
您可以使用 janitor
package, especially the function excel_numeric_to_date
.
另一种选择是使用包 readxl
读取您的 excel 文件,该文件会自动转换日期时间中的日期列:
library(readxl)
read_excel("services_subsectors_sa_m_nace2.xlsx", sheet="73")