楼主: zhangshy
3736 1

[问答] R中如何将读入的CSV格式日期,变为日期格式 [推广有奖]

  • 0关注
  • 2粉丝

已卖:283份资源

本科生

45%

还不是VIP/贵宾

-

威望
0
论坛币
222 个
通用积分
0.2400
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1083 点
帖子
45
精华
0
在线时间
104 小时
注册时间
2005-5-14
最后登录
2021-9-16

楼主
zhangshy 发表于 2013-12-12 15:08:51 |AI写论文
5论坛币
我有一个CSV文件,读入R后原来的日期变成了因子格式如“2013-10-15”,怎么把它转化为R认可的日期格式,谢谢了

关键词:如何

沙发
zhangyangsmith 发表于 2013-12-12 19:00:57
Use "strptime" function: suppose your variable is named "dt", the following cmd will give you the date in the format recognized by R:
  1. strptime(dt, format = "%Y-%m-%d")
复制代码
Optionally, you may want to read your data using "stringsAsFactors=FALSE" so that the date will be read as string and when using "strptime" function you can avoid the implicit covert the factor back to string.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-20 21:13