[英]Year to Year-Month-Day format
I have a datafile in the following format: 我有以下格式的数据文件:
Year Observed Flow Simulated Flow
2000 210 256
2001 560 568
2002 435 896
2003 58 95
---- ---- ----
Using plot2(...)gives the graph of observed and simulated flows in Y axis and Year in x axis (one graph). 使用plot2(...)可以在Y轴上观察到和模拟的流量,在x轴上可以看到Year(一张)。 However, all Year format did not appear in the graph, rather it appeared as 1, 2, 3...etc.
但是,所有Year格式都没有出现在图形中,而是显示为1、2、3 ...等。 But I want to see the x-axis label in actual Year format like 2000, 2001, 2002, 2003...etc.
但是我想以实际的Year格式查看x轴标签,例如2000、2001、2002、2003 ...等。
I tried using as.Date(...) and some other commands like as.POSIXct, however, couldn't able to convert 'Year' to "Year-Month-Day" format. 我尝试使用as.Date(...)和其他一些命令(例如as.POSIXct),无法将“年”转换为“年月日”格式。 The idea of converting Year into Year-Month-Day format is to read the data using read.zoo command, and thus, utilize plot2(....).
将Year转换为Year-Month-Day格式的想法是使用read.zoo命令读取数据,从而利用plot2(....)。
So the question is: How can I convert "Year" column to "Year-Month-Day" column so that the data would look like this: 所以问题是:如何将“年”列转换为“年-月-日”列,以便数据看起来像这样:
Date Observed Flow Simulated Flow
2000-01-01 210 256
2001-01-01 560 568
2002-01-01 435 896
2003-01-01 58 95
---------- ---- ----
You can cheat a little, 你可以作弊一点
You want to add -01-01 to the end of every date so that you can nicely convert it to a date. 您想在每个日期的末尾添加-01-01,以便将其很好地转换为日期。
data$Date = as.Date(paste0(data$Year,'-01-01'))
should work 应该管用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.