gpt4 book ai didi

string - 从 data.frame 中的日期中删除斜杠

转载 作者:行者123 更新时间:2023-12-05 08:58:22 25 4
gpt4 key购买 nike

我在 x <- data.frame(01/01/2009) 形式的 data.frame 中有一系列日期。我想将系列更改为 01012009 形式。我尝试了 gsub("//",""x) 但它似乎不起作用。

我只想删除 back 正斜杠。任何帮助将不胜感激。

最佳答案

另一种方法是在R中使用as.Date/strftime等日期时间操作函数

# create a Date column (can do things with dates as dates now)
dat$Date <- as.Date(as.character(dat$dates),format = '%d/%m/%Y')
# create character column with format of your desire
dat$newDate <- strftime(dat$Date, '%d%m%Y')

关于string - 从 data.frame 中的日期中删除斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24005195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com