我有一个包含时间戳(m/d/yyyy H:M)的数据框。我的最终目标是通过使用时间戳(例如每小时、每天、每天的小时子集等)来总结数据。
导入我正在使用的数据时read.csv
。第一列是时间戳。当我使用read.csv
. 我应该在读入参数时使用row.names
参数,还是应该将因子转换为时间戳?
如果我应该转换,我的时间戳目前是不明确的,我可以在读取之前转换为 YYYY/MM/DD HH:MM:SS(在 Excel 中?),然后用于as.POSIXct
从因子中转换。或者,我可以保持原样并使用strptime
从因子转换。这些选项之一是否更适合我的最终目标?
我在尝试使用适用于我自己的数据集的示例数据中的代码时遇到了问题。因此,我希望当程序变得更加复杂时,这个更基本的问题将导致未来的成功。
#dput of partial dataset
data <- structure(list(TIMESTAMP = structure(1:15, .Label = c("1/1/2012 11:00",
"1/1/2012 12:00", "1/1/2012 13:00", "1/1/2012 14:00", "1/1/2012 15:00",
"1/2/2012 11:00", "1/2/2012 12:00", "1/2/2012 13:00", "1/2/2012 14:00",
"1/2/2012 15:00", "4/7/2012 11:00", "4/7/2012 12:00", "4/7/2012 13:00",
"4/7/2012 14:00", "4/7/2012 15:00"), class = "factor"), P = c(992.4,
992.4, 992.4, 992.4, 992.4, 992.4, 992.4, 992.4, 992.4, 992.4,
239, 239, 239, 239, 239), WS = c(4.023, 3.576, 4.023, 6.259,
4.47, 3.576, 3.576, 2.682, 4.023, 3.576, 2.682, 3.129, 2.682,
2.235, 2.682), WD = c(212L, 200L, 215L, 213L, 204L, 304L, 276L,
273L, 307L, 270L, 54L, 24L, 304L, 320L, 321L), AT = c(16.11,
18.89, 20, 20, 19.44, 10.56, 11.11, 11.67, 12.22, 11.11, 17.22,
18.33, 19.44, 20.56, 21.11), FT = c(17.22, 22.22, 22.78, 22.78,
20, 11.11, 15.56, 17.22, 17.78, 15.56, 24.44, 25.56, 29.44, 30.56,
29.44), H = c(50L, 38L, 38L, 39L, 48L, 24L, 19L, 18L, 16L, 18L,
23L, 20L, 18L, 17L, 15L), B = c(1029L, 1027L, 1026L, 1024L, 1023L,
1026L, 1025L, 1024L, 1023L, 1023L, 1034L, 1033L, 1032L, 1031L,
1030L), FM = c(14.9, 14.4, 14, 13.7, 13.6, 13.1, 12.8, 12.3,
12, 11.7, 12.8, 12, 11.4, 10.9, 10.4), GD = c(204L, 220L, 227L,
222L, 216L, 338L, 311L, 326L, 310L, 273L, 62L, 13L, 312L, 272L,
281L), MG = c(8.047, 9.835, 10.28, 13.41, 11.18, 9.388, 8.941,
8.494, 9.835, 10.73, 6.706, 7.153, 8.047, 8.047, 7.6), SR = c(522L,
603L, 604L, 526L, 248L, 569L, 653L, 671L, 616L, 487L, 972L, 1053L,
1061L, 1002L, 865L), WS2 = c(2.235, 3.576, 4.47, 4.47, 5.364,
4.023, 2.682, 3.576, 3.576, 4.023, 3.129, 3.129, 3.576, 2.682,
3.129), WD2 = c(200L, 201L, 206L, 210L, 211L, 319L, 315L, 311L,
302L, 290L, 49L, 39L, 15L, 348L, 329L)), .Names = c("TIMESTAMP",
"P", "WS", "WD", "AT", "FT", "H", "B", "FM", "GD", "MG", "SR",
"WS2", "WD2"), class = "data.frame", row.names = c(NA, -15L))