使用write.csv时将字符转换为日期 [英] characters converted to dates when using write.csv

查看:161
本文介绍了使用write.csv时将字符转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据框的A列包含字符形式的字符串

my data frame has a column A with strings in character form

> df$A
[1] "2-60", "2-61", "2-62", "2-63" etc

我使用write.csv保存了该表,但是当我使用Excel打开它时,列A的格式设置为日期:

I saved the table using write.csv, but when I open it with Excel column A appears formatted as date:

Feb-60
Feb-61
Feb-62
Feb-63
etc

任何人都知道我该怎么做才能避免这种情况?

Anyone knows what can I do to avoid this?

我调整了write.csv的参数,但没有任何效果,而且我似乎在Stack Overflow中找不到一个有助于解决此问题的示例.

I tweaked the arguments of write.csv but nothing worked, and I can't seem to find an example in Stack Overflow that helps solve this problem.

推荐答案

另一种解决方案-有点乏味,请在Excel中使用导入文本文件",单击对话框,然后在文本导入向导"的第3步(共3步)中您可以选择设置列数据格式,对具有"2-60","2-61","2-62","2-63"的列使用文本".如果您使用常规"(默认设置),则Excel会尝试变得智能并为您转换答案.

Another solution - a bit tedious, Use Import Text File in Excel, click thru the dialog boxes and in Step 3 of 3 of the Text Import Wizard, you will have an option of setting the column data format, use "Text" for the column that has "2-60", "2-61", "2-62", "2-63". If you use General (the default), Excel tries to be smart and converts the answer for you.

这篇关于使用write.csv时将字符转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆