将时间戳写入CSV文件 [英] Writing timestamps to a CSV file

查看:572
本文介绍了将时间戳写入CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在输出CSV文件中写入时间戳。时间戳格式2013-08-28 01:02

I want to write timestamp in output CSV file. Timestamp in format "2013-08-28 01:02"

基本上我想写3个参数让我们说在一个输出文件中的 a b timestamp 我从数据文件中读取 a b in.nc ),现在需要一个输出文件( out.csv ),其输出如下:

Basically I want to write 3 parameters lets say a, b and timestamp in one output file. I am reading a and b from a data file (in.nc) and now want a output file (out.csv) which will have output like this:

2013-08-28 01:02,0.2,20

2013-08-28 02:02,0.1,30

2013-08-28 03:02,1,40

2013-08-28 03:02,4,80

我在输入文件中没有时间戳,必须在程序中创建一个在输出文件中写入。

I have no timestamp in input file and has to create one in program to write in output file.

推荐答案

假设您要从创建一小时间隔数据2013-08-28 01 :02:00

 #input data
 Input <- data.frame(Column1 = c(0.3, 0.5, 0.2, 0.8), Column2=c(20,40,50,90))

 Output <- data.frame(datetime=seq(as.POSIXct("2013-08-28 01:02:00"),
                                         length=4, by="1 hour"), Input)



 Output
 #            datetime Column1 Column2
 #1 2013-08-28 01:02:00     0.3      20
 #2 2013-08-28 02:02:00     0.5      40
 #3 2013-08-28 03:02:00     0.2      50
 #4 2013-08-28 04:02:00     0.8      90

现在,您可以使用 write.csv write.table

这篇关于将时间戳写入CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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