大家好!我一直在尝试使用read.xlsx()函数将一些数据从Excel文件读入R中。我的日期范围为1843年。我尝试了在线提供的各种技巧,但无法获得正确的日期格式。如果有人可以提供任何建议,那将是很大的帮助。非常感谢。
答案 0 :(得分:0)
df <- tibble(
DOB = c(19644, 29571, 19744, 22557, 28258, 24366)
)
df_2 <- df %>%
mutate(DOB = DOB %>%
as.character %>% # First convert the factors into character strings
as.numeric %>% # ...and then to numeric days since origin
as.Date(origin = "1899-12-30") # ...and finally to a date
)
# Note: for Excel on Mac, the origin is "1904-01-01" because Think Different.