I want to aggregate against the Time column that is read in as a string and then subset the output but I can’t convert the output tmp$Time to Time value.
Data was created by reading in a csv file.
> head(Data)
Time F Z
1 2011-09-09-06.54.00 1 489
2 2011-09-09-06.54.00 3 678
3 2011-09-09-06.54.00 6 890
4 2011-09-09-07.54.00 8 345
5 2011-09-09-07.54.00 10 567
> strptime(Data$Time, format="%Y-%m-%d-%H.%M.%S" )
[1] "2011-09-09 06:54:00" "2011-09-09 06:54:00"
[3] "2011-09-09 06:54:00" "2011-09-09 07:54:00"
[5] "2011-09-09 07:54:00"
> tmp <- aggregate(Data$Z ~ Data$Time,Data, sum)
> head(tmp)
Data$Time Data$Z
1 2011-09-09-06.54.00 2057
2 2011-09-09-07.54.00 912
> strptime(tmp[1], format="%Y-%m-%d-%H.%M.%S" )
Data$Time
NA
I am using aggregate against the Time value before converting it because I can’t get it to work against Time when it is a time.
This seems to work
producing
I made two changes to your final line:
tmp[,1]rather thantmp[1]format="%Y-%m-%d %H:%M:%S"rather thanformat="%Y-%m-%d-%H.%M.%S"