我有一些看起来像这样的数据:
# Date Time Temp Intensity Coupler Attached Host Connected Stopped End Of File
1 05/28/15 06:00:00.0 20.329 893.4
2 05/28/15 07:00:00.0 21.76 5 511.1
3 05/28/15 08:00:00.0 36.946 79 911.6
4 05/28/15 09:00:00.0 40.761 60 622.6
5 05/28/15 10:00:00.0 41.225 24 800.2
6 05/28/15 11:00:00.0 29.853 14 466.8
7 05/28/15 12:00:00.0 26.195 5 511.1
8 05/28/15 13:00:00.0 28.06 9 300.1
9 05/28/15 14:00:00.0 27.468 6 544.5
10 05/28/15 15:00:00.0 26.879 4 133.4
11 05/28/15 16:00:00.0 26 2 238.9
12 05/28/15 17:00:00.0 25.513 1 173.3
13 05/28/15 18:00:00.0 24.738 75.3
14 05/28/15 19:00:00.0 24.062 0
15 05/28/15 20:00:00.0 23.773 0
16 05/28/15 21:00:00.0 23.292 0
17 05/28/15 22:00:00.0 22.812 0
18 05/28/15 23:00:00.0 22.429 0
19 05/29/15 00:00:00.0 22.046 0
20 05/29/15 01:00:00.0 21.76 0
21 05/29/15 02:00:00.0 21.473 0
22 05/29/15 03:00:00.0 21.091 0
23 05/29/15 04:00:00.0 20.901 0
24 05/29/15 05:00:00.0 20.615 0
25 05/29/15 06:00:00.0 20.901 1 894.5
26 05/29/15 07:00:00.0 22.525 8 611.2
27 05/29/15 08:00:00.0 29.652 42 711.4
28 05/29/15 09:00:00.0 36.079 22 44.6
29 05/29/15 10:00:00.0 39.729 77 156.1
30 05/29/15 11:00:00.0 31.37 19 289
31 05/29/15 12:00:00.0 32.086 7 233.4
我试图使用聚合函数来获得每个时间点的平均温度。我用这个函数:
aggregate(x=trap7u$Temp,by=list(trap7u$Time),FUN=mean)
这给出了以下输出:
Group.1 x
1 06:00:00 NA
R不会返回任何错误,只是上面的数据。我试图将列转换为不同的东西,并尝试删除任何NA,这会返回相同的结果。
str(trap7u)
返回:
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 1770 obs. of 9 variables:
$ # : int 1 2 3 4 5 6 7 8 9 10 ...
$ Date : chr "05/28/15" "05/28/15" "05/28/15" "05/28/15" ...
$ Time :Classes 'hms', 'difftime' atomic [1:1770] 21600 25200 28800 32400 36000 39600 43200 46800 50400 54000 ...
.. ..- attr(*, "units")= chr "secs"
$ Temp : num 20.3 21.8 36.9 40.8 41.2 ...
$ Intensity : num 893 5 79 60 24 ...
$ Coupler Attached: num NA 511 912 623 800 ...
$ Host Connected : chr NA NA NA NA ...
$ Stopped : chr NA NA NA NA ...
$ End Of File : chr NA NA NA NA ...
- attr(*, "problems")=Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 1 obs. of 5 variables:
..$ row : int 1769
..$ col : chr "Coupler Attached"
..$ expected: chr "a double"
..$ actual : chr "Logged"
..$ file : chr "'~/Desktop/bioinformatic_work/HOBO_files_complete/hobo_files/2015-AUG-offload/trap7u_10733861_150809.csv'"
- attr(*, "spec")=List of 2
..$ cols :List of 9
.. ..$ # : list()
.. .. ..- attr(*, "class")= chr "collector_integer" "collector"
.. ..$ Date : list()
.. .. ..- attr(*, "class")= chr "collector_character" "collector"
.. ..$ Time :List of 1
.. .. ..$ format: chr ""
.. .. ..- attr(*, "class")= chr "collector_time" "collector"
.. ..$ Temp : list()
.. .. ..- attr(*, "class")= chr "collector_double" "collector"
.. ..$ Intensity : list()
.. .. ..- attr(*, "class")= chr "collector_double" "collector"
.. ..$ Coupler Attached: list()
.. .. ..- attr(*, "class")= chr "collector_double" "collector"
.. ..$ Host Connected : list()
.. .. ..- attr(*, "class")= chr "collector_character" "collector"
.. ..$ Stopped : list()
.. .. ..- attr(*, "class")= chr "collector_character" "collector"
.. ..$ End Of File : list()
.. .. ..- attr(*, "class")= chr "collector_character" "collector"
..$ default: list()
.. ..- attr(*, "class")= chr "collector_guess" "collector"
..- attr(*, "class")= chr "col_spec"
我想要得到的是每次的平均温度值,我该如何实现?