I have several days of heart rate data for every second of the day (with random missing gaps of data) like this:
structure(list(TimePoint = structure(c(1523237795, 1523237796,
1523237797, 1523237798, 1523237799, 1523237800, 1523237801, 1523237802,
1523237803, 1523237804), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
HR = c(80L, 83L, 87L, 91L, 95L, 99L, 102L, 104L, 104L, 103L
)), row.names = c(NA, 10L), class = "data.frame")
------------------------------
TimePoint HR
1 2018-04-09 01:36:35 80
2 2018-04-09 01:36:36 83
3 2018-04-09 01:36:37 87
4 2018-04-09 01:36:38 91
5 2018-04-09 01:36:39 95
6 2018-04-09 01:36:40 99
7 2018-04-09 01:36:41 102
8 2018-04-09 01:36:42 104
9 2018-04-09 01:36:43 104
10 2018-04-09 01:36:44 103
.
.
.
I would like to apply the Scale(center = T, scale = T) function to the data to normalize across participants.
However, I don't want to normalize across entire days of available data, but across every 24 hour period
So if a participant has 3 days of data, the HR will be scaled to a z-distribution 3 separate times; each for it's respective day
I am having trouble doing this successfully.
# read csv
DF = read.csv(x)
# make sure date stamp is read YYYY Month Day & convert timestamp into class POSIXct
x2 = as.POSIXct(DF[,1], format = '%d.%m.%Y %H:%M:%S', tz = "UTC") %>% data.frame()
# rename column
colnames(x2)[1] = "TimePoint"
# add the participant HR data to this dataframe
x2$HR = DF[,2]
# break time stamps into 60 minute windows
by60 = cut(x2$TimePoint, breaks = "60 min")
# get the average HR per 60 min window
DF_Sum = aggregate(HR ~ by60, FUN=mean, data=x2)
# add weekday /hours for future plot visualization
DF_Sum$WeekDay = wday(DF_Sum$by60, label = T)
DF_Sum$Hour = hour(DF_Sum$by60)
I am able to split the data by timeseries and average the HR by hour but I cannot seem to add the scale function properly.
Help appreciated.
Create time intervals of 24 hours for each patient, group_by patient and time intervals, then calculate the scaled HR for each group.
library(dplyr)
df %>%
#remove the following mutate and replace ID in group_by by the ID's column name in your data set
mutate(ID=1) %>%
group_by(ID, Int=cut(TimePoint, breaks="24 hours")) %>%
mutate(HR_sc=scale(HR, center = TRUE, scale = TRUE))
# A tibble: 10 x 5
# Groups: ID, Int [1]
TimePoint HR ID Int HR_sc
<dttm> <int> <dbl> <fct> <dbl>
1 2018-04-09 01:26:35 80 1 2018-04-09 01:00:00 -1.63
2 2018-04-09 01:28:16 83 1 2018-04-09 01:00:00 -1.30
3 2018-04-09 01:29:57 87 1 2018-04-09 01:00:00 -0.860
4 2018-04-09 01:31:38 91 1 2018-04-09 01:00:00 -0.419
5 2018-04-09 01:33:19 95 1 2018-04-09 01:00:00 0.0221
6 2018-04-09 01:33:20 99 1 2018-04-09 01:00:00 0.463
7 2018-04-09 01:35:01 102 1 2018-04-09 01:00:00 0.794
8 2018-04-09 01:36:42 104 1 2018-04-09 01:00:00 1.01
9 2018-04-09 01:38:23 104 1 2018-04-09 01:00:00 1.01
10 2018-04-09 01:39:59 103 1 2018-04-09 01:00:00 0.905
Related
I have a dataset of temperature values taken at specific datetimes across five locations. For whatever reason, sometimes the readings are every hour, and some every four hours. Another issue is that when the time changed as a result of daylight savings, the readings are off by one hour. I am interested in the readings taken every four hours and would like to subset these by day and night to ultimately get daily and nightly mean temperatures.
To summarise, the readings I am interested in are either:
0800, 1200, 1600 =day
2000, 0000, 0400 =night
Recordings between 0800-1600 and 2000-0400 each day should be averaged.
During daylight savings, the equivalent times are:
0900, 1300, 1700 =day
2100, 0100, 0500 =night
Recordings between 0900-1700 and 2100-0500 each day should be averaged.
In the process, I am hoping to subset by site.
There are also some NA values or blank cells which should be ignored.
So far, I tried to subset by one hour of interest just to see if it worked, but haven't got any further than that. Any tips on how to subset by a series of times of interest? Thanks!
temperature <- read.csv("SeaTemperatureData.csv",
stringsAsFactors = FALSE)
temperature <- subset(temperature, select=-c(X)) #remove last column that contains comments, not needed
temperature$Date.Time < -as.POSIXct(temperature$Date.Time,
format="%d/%m/%Y %H:%M",
tz="Pacific/Auckland")
#subset data by time, we only want to include temperatures recorded at certain times
temperature.goat <- subset(temperature, Date.Time==c('01:00:00'), select=c("Goat.Island"))
Date.Time Goat.Island Tawharanui Kawau Tiritiri Noises
1 2019-06-10 16:00:00 16.820 16.892 16.749 16.677 15.819
2 2019-06-10 20:00:00 16.773 16.844 16.582 16.654 15.796
3 2019-06-11 00:00:00 16.749 16.820 16.749 16.606 15.819
4 2019-06-11 04:00:00 16.487 16.796 16.654 16.558 15.796
5 2019-06-11 08:00:00 16.582 16.749 16.487 16.463 15.867
6 2019-06-11 12:00:00 16.630 16.773 16.725 16.654 15.867
One possible solution is to extract hours from your DateTime variable, then filter for particular hours of interest.
Here a fake example over 4 days:
library(lubridate)
df <- data.frame(DateTime = seq(ymd_hms("2020-02-01 00:00:00"), ymd_hms("2020-02-05 00:00:00"), by = "hour"),
Value = sample(1:100,97, replace = TRUE))
DateTime Value
1 2020-02-01 00:00:00 99
2 2020-02-01 01:00:00 51
3 2020-02-01 02:00:00 44
4 2020-02-01 03:00:00 49
5 2020-02-01 04:00:00 60
6 2020-02-01 05:00:00 56
Now, you can extract hours with hour function of lubridate and subset for the desired hour:
library(lubridate)
subset(df, hour(DateTime) == 5)
DateTime Value
6 2020-02-01 05:00:00 56
30 2020-02-02 05:00:00 31
54 2020-02-03 05:00:00 65
78 2020-02-04 05:00:00 80
EDIT: Getting mean of each sites per subset of hours
Per OP's request in comments, the question is to calcualte the mean of values for various sites for different period of times.
Basically, you want to have two period per days, one from 8:00 to 17:00 and the other one from 18:00 to 7:00.
Here, a more elaborated example based on the previous one:
df <- data.frame(DateTime = seq(ymd_hms("2020-02-01 00:00:00"), ymd_hms("2020-02-05 00:00:00"), by = "hour"),
Site1 = sample(1:100,97, replace = TRUE),
Site2 = sample(1:100,97, replace = TRUE))
DateTime Site1 Site2
1 2020-02-01 00:00:00 100 6
2 2020-02-01 01:00:00 9 49
3 2020-02-01 02:00:00 86 12
4 2020-02-01 03:00:00 34 55
5 2020-02-01 04:00:00 76 29
6 2020-02-01 05:00:00 41 1
....
So, now you can do the following to label each time point as daily or night, then group by this category for each day and calculate the mean of each individual sites using summarise_at:
library(lubridate)
library(dplyr)
df %>% mutate(Date = date(DateTime),
Hour= hour(DateTime),
Category = ifelse(between(hour(DateTime),8,17),"Daily","Night")) %>%
group_by(Date, Category) %>%
summarise_at(vars(c(Site1,Site2)), ~ mean(., na.rm = TRUE))
# A tibble: 9 x 4
# Groups: Date [5]
Date Category Site1 Site2
<date> <chr> <dbl> <dbl>
1 2020-02-01 Daily 56.9 63.1
2 2020-02-01 Night 58.9 46.6
3 2020-02-02 Daily 54.5 47.6
4 2020-02-02 Night 36.9 41.7
5 2020-02-03 Daily 42.3 56.9
6 2020-02-03 Night 44.1 55.9
7 2020-02-04 Daily 54.3 50.4
8 2020-02-04 Night 54.8 34.3
9 2020-02-05 Night 75 16
Does it answer your question ?
I am trying to use group_by and then summarise using date difference calculation. I am not sure if its a runtime error or something wrong in what I am doing. Sometimes when I run the code I get the output as days and other times as seconds. I am not sure what is causing this change. I am not changing dataset or codes. The dataset I am using is huge (2,304,433 rows and 40 columns). Both the times, the output value (digits) are the same but only the name changes (days to secs). I would like to see the output in days.
This is the code that I am using:
data %>%
group_by(PRODUCT,PERSON_ID) %>%
summarise(Freq = n(),
Revenue = max(TOTAL_AMT + 0.000001/QUANTITY),
No_Days = (max(ORDER_DT) - min(ORDER_DT) + 1)/n())
This is the output.
Can anyone please help me on this?
Use difftime() You might need to specify the units.
set.seed(314)
data <- data.frame(PRODUCT = sample(1:10, size = 10000, replace = TRUE),
PERSON_ID = sample(1:10, size = 10000, replace = TRUE),
ORDER_DT = as.POSIXct(as.Date('2019/01/01') + sample(-300:+300, size = 10000, replace = TRUE)))
require(dplyr)
data %>%
group_by(PRODUCT,PERSON_ID) %>%
summarise(Freq = n(),
start = min(ORDER_DT),
end = max(ORDER_DT)) %>%
mutate(No_Days = (as.double(difftime(end, start, units = "days"), units = "days")+1)/Freq)
gives:
PRODUCT PERSON_ID Freq start end No_Days
<int> <int> <int> <dttm> <dttm> <dbl>
1 1 1 109 2018-03-21 01:00:00 2019-10-27 02:00:00 5.38
2 1 2 117 2018-03-23 01:00:00 2019-10-26 02:00:00 4.98
3 1 3 106 2018-03-19 01:00:00 2019-10-28 01:00:00 5.56
4 1 4 109 2018-03-07 01:00:00 2019-10-26 02:00:00 5.50
5 1 5 95 2018-03-07 01:00:00 2019-10-16 02:00:00 6.2
6 1 6 79 2018-03-09 01:00:00 2019-10-04 02:00:00 7.28
7 1 7 83 2018-03-09 01:00:00 2019-10-28 01:00:00 7.22
8 1 8 114 2018-03-09 01:00:00 2019-10-16 02:00:00 5.15
9 1 9 100 2018-03-09 01:00:00 2019-10-13 02:00:00 5.84
10 1 10 91 2018-03-11 01:00:00 2019-10-26 02:00:00 6.54
# ... with 90 more rows
Why is the value devided by n()?
Simple as.integer(max(ORDER_DT) - min(ORDER_DT)) should work, but if it doesn't then please be more specific and update me with more information.
Also while working with datetime values it's good to know lubridate library
I have a large dataset over many years which has several variables, but the one I am interested in is wind speed and dateTime. I want to find the time of the max wind speed for every day in the data set. I have hourly data in Posixct format, with WS as a numeric with occasional NAs. Below is a short data set that should hopefully illustrate my point, however my dateTime wasn't working out to be hourly data, but it provides enough for a sample.
dateTime <- seq(as.POSIXct("2011-01-01 00:00:00", tz = "GMT"),
as.POSIXct("2011-01-29 23:00:00", tz = "GMT"),
by = 60*24)
WS <- sample(0:20,1798,rep=TRUE)
WD <- sample(0:390,1798,rep=TRUE)
Temp <- sample(0:40,1798,rep=TRUE)
df <- data.frame(dateTime,WS,WD,Temp)
df$WS[WS>15] <- NA
I have previously tried creating a new column with just a posix date (minus time) to allow for day isolation, however all the things I have tried have only returned a shortened data frame with date and WS (aggregate, splitting, xts). Aggregate was only one that didn't do this, however, it gave me 23:00:00 as a constant time which isn't correct.
I have looked at How to calculate daily means, medians, from weather variables data collected hourly in R?, https://stats.stackexchange.com/questions/7268/how-to-aggregate-by-minute-data-for-a-week-into-hourly-means and others but none have answered this question, or the solutions have not returned an ideal result.
I need to compare the results of this analysis with another data frame, so hence the reason I need the actual time when the max wind speed occurred for each day in the dataset. I have a feeling there is a simple solution, however, this has me frustrated.
A dplyr solution may be:
library(dplyr)
df %>%
mutate(date = as.Date(dateTime)) %>%
left_join(
df %>%
mutate(date = as.Date(dateTime)) %>%
group_by(date) %>%
summarise(max_ws = max(WS, na.rm = TRUE)) %>%
ungroup(),
by = "date"
) %>%
select(-date)
# dateTime WS WD Temp max_ws
# 1 2011-01-01 00:00:00 NA 313 2 15
# 2 2011-01-01 00:24:00 7 376 1 15
# 3 2011-01-01 00:48:00 3 28 28 15
# 4 2011-01-01 01:12:00 15 262 24 15
# 5 2011-01-01 01:36:00 1 149 34 15
# 6 2011-01-01 02:00:00 4 319 33 15
# 7 2011-01-01 02:24:00 15 280 22 15
# 8 2011-01-01 02:48:00 NA 110 23 15
# 9 2011-01-01 03:12:00 12 93 15 15
# 10 2011-01-01 03:36:00 3 5 0 15
Dee asked for: "I want to find the time of the max wind speed for every day in the data set." Other answers have calculated the max(WS) for every day, but not at which hour that occured.
So I propose the following solution with dyplr:
library(dplyr)
set.seed(12345)
dateTime <- seq(as.POSIXct("2011-01-01 00:00:00", tz = "GMT"),
as.POSIXct("2011-01-29 23:00:00", tz = "GMT"),
by = 60*24)
WS <- sample(0:20,1738,rep=TRUE)
WD <- sample(0:390,1738,rep=TRUE)
Temp <- sample(0:40,1738,rep=TRUE)
df <- data.frame(dateTime,WS,WD,Temp)
df$WS[WS>15] <- NA
df %>%
group_by(Date = as.Date(dateTime)) %>%
mutate(Hour = hour(dateTime),
Hour_with_max_ws = Hour[which.max(WS)])
I want to highlight out, that if there are several hours with the same maximal windspeed (in the example below: 15), only the first hour with max(WS) will be shown as result, though the windspeed 15 was reached on that date at the hours 0, 3, 4, 21 and 22! So you might need a more specific logic.
For the sake of completeness (and because I like the concise code) here is a "one-liner" using data.table:
library(data.table)
setDT(df)[, max.ws := max(WS, na.rm = TRUE), by = as.IDate(dateTime)][]
dateTime WS WD Temp max.ws
1: 2011-01-01 00:00:00 NA 293 22 15
2: 2011-01-01 00:24:00 15 55 14 15
3: 2011-01-01 00:48:00 NA 186 24 15
4: 2011-01-01 01:12:00 4 300 22 15
5: 2011-01-01 01:36:00 0 120 36 15
---
1734: 2011-01-29 21:12:00 12 249 5 15
1735: 2011-01-29 21:36:00 9 282 21 15
1736: 2011-01-29 22:00:00 12 238 6 15
1737: 2011-01-29 22:24:00 10 127 21 15
1738: 2011-01-29 22:48:00 13 297 0 15
I have a set of time series data that has a start and stop time. Each event can last from few seconds to few days, I need to calculate the sum, in this example the total memory used, every hour of the jobs active at the time. Here is a sample of the data:
mem_used start_time stop_time
16 2015-10-24 17:24:41 2015-10-25 04:19:44
80 2015-10-24 17:24:51 2015-10-25 03:14:59
44 2015-10-24 17:25:27 2015-10-25 01:16:10
28 2015-10-24 17:25:43 2015-10-25 00:00:31
72 2015-10-24 17:30:23 2015-10-24 23:58:31
In this case it should give something like:
time total_mem
2015-10-24 17:00:00 240
2015-10-24 18:00:00 240
...
2015-10-25 00:00:00 168
2015-10-25 01:00:00 140
2015-10-25 02:00:00 96
2015-10-25 03:00:00 96
2015-10-25 04:00:00 16
I'm trying to do something with the aggregate function but I can not figure it out. Any ideas? Thanks.
Here's how I would do it, using lubridate.
First, make sure that your dates are in POSIXct format:
dat$start_time = as.POSIXct(dat$start_time, format = "%Y-%m-%d %H:%M:%S")
dat$stop_time = as.POSIXct(dat$stop_time, format = "%Y-%m-%d %H:%M:%S")
Then make an interval object with lubridate:
library(lubridate)
dat$interval <- interval(dat$start_time, dat$stop_time)
Now we can make a vector of times, replace these with your desired times:
z <- seq(start = dat$start_time[1], stop = dat$stop_time[5], by = "hours")
And sum those where we have an overlap:
out <- data.frame(times = z,
mem_used = sapply(z, function(x) sum(dat$mem_used[x %within% dat$interval])))
times mem_used
1 2015-10-24 17:24:41 16
2 2015-10-24 18:24:41 240
3 2015-10-24 19:24:41 240
4 2015-10-24 20:24:41 240
5 2015-10-24 21:24:41 240
6 2015-10-24 22:24:41 240
7 2015-10-24 23:24:41 240
Here's the data used:
structure(list(mem_used = c(16L, 80L, 44L, 28L, 72L), start_time = structure(c(1445721881,
1445721891, 1445721927, 1445721943, 1445722223), class = c("POSIXct",
"POSIXt"), tzone = ""), stop_time = structure(c(1445761184, 1445757299,
1445750170, 1445745631, 1445745511), class = c("POSIXct", "POSIXt"
), tzone = "")), .Names = c("mem_used", "start_time", "stop_time"
), row.names = c(NA, -5L), class = "data.frame")
Here is another solution based on dplyr and lubridate.
Make sure first to have the data in the right format (e.g date in POSIXct)
library(dplyr)
library(lubridate)
glimpse(df)
## Observations: 5
## Variables: 3
## $ mem_used (int) 16, 80, 44, 28, 72
## $ start_time (time) 2015-10-24 17:24:41, 2015-10-24 17:24:51...
## $ end_time (time) 2015-10-25 04:19:44, 2015-10-25 03:14:59...
Then we will just keep the hour (removing minutes and seconds) since we want to aggregate per hour.
### Remove minutes and seconds
minute(df$start_time) <- 0
second(df$start_time) <- 0
minute(df$end_time) <- 0
second(df$end_time) <- 0
The most important step now, is to create a new data.frame with one row for each hour between start_time and end_time. For example, if on the first line of the original data.frame we have 5 hours between start_time and end_time, we will end with 5 rows and the value mem_used duplicated 5 times.
###
n <- nrow(df)
l <- lapply(1:n, function(i) {
date <- seq.POSIXt(df$start_time[i], df$end_time[i], by = "hour")
mem_used <- rep(df$mem_used[i], length(date))
data.frame(time = date, mem_used = mem_used)
})
df <- Reduce(rbind, l)
glimpse(df)
## Observations: 47
## Variables: 2
## $ time (time) 2015-10-24 17:00:00, 2015-10-24 18:00:00, ...
## $ mem_used (int) 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,...
Finally, we can now aggregate using dplyr or aggregate (or other similar functions)
df %>%
group_by(time) %>%
summarise(tot = sum(mem_used))
## time tot
## (time) (int)
## 1 2015-10-24 17:00:00 240
## 2 2015-10-24 18:00:00 240
## 3 2015-10-24 19:00:00 240
## 4 2015-10-24 20:00:00 240
## 5 2015-10-24 21:00:00 240
## 6 2015-10-24 22:00:00 240
## 7 2015-10-24 23:00:00 240
## 8 2015-10-25 00:00:00 168
## 9 2015-10-25 01:00:00 140
## 10 2015-10-25 02:00:00 96
## 11 2015-10-25 03:00:00 96
## 12 2015-10-25 04:00:00 16
## Or aggregate
aggregate(mem_used ~ time, FUN = sum, data = df)
I am looking to take a dataframe which has data ordered through time and aggregate up to the hourly level, and place the data into a separate dataframe. It's best explained with an example:
tradeData dataframe:
Time Amount
2014-05-16 14:00:05 10
2014-05-16 14:00:10 20
2014-05-16 14:08:15 30
2014-05-16 14:23:09 51
2014-05-16 14:59:54 84
2014-05-16 15:09:45 94
2014-05-16 15:24:41 53
2014-05-16 16:30:51 44
The matrix above contains the data I would like to aggregate. Below is the dataframe into which I would like to insert it:
HourlyData dataframe:
Time Profit
2014-05-16 00:00:00 100
2014-05-16 01:00:00 200
2014-05-16 02:00:00 250
...
2014-05-16 14:00:00 30
2014-05-16 15:00:00 -50
2014-05-16 16:00:00 67
...
2014-05-16 23:00:00 -8
I would like to aggregate the data in the tradeData dataframe and place it in the correct place in the hourlyData dataframe as below:
New hourlyData dataframe:
Time Profit Amount
2014-05-16 00:00:00 100 0
2014-05-16 01:00:00 200 0
2014-05-16 02:00:00 250 0
...
2014-05-16 14:00:00 30 0
2014-05-16 15:00:00 -50 195 (10+20+30+51+84)
2014-05-16 16:00:00 67 147 (94+53)
2014-05-16 17:00:00 20 44
...
2014-05-16 23:00:00 -8 0
Using the solution provided by Akrun below, I was able to get a solution for most instances. However, there appears to be an issue when an event occurs within the last hour of the day, as below:
TradeData
Time Amount
2014-08-15 22:09:07 11037.778
2014-08-15 23:01:33 13374.724
2014-08-20 23:25:40 133373.000
HourlyData
Time Amount
2014-08-15 23:00:00 11037.778 (correct)
2014-08-18 00:00:00 0 (incorrect)
2014-08-21 00:00:00 133373 (correct)
The formula appears to be skip the data for the second trade in the tradeData dataframe when aggregating in the hourlyData dataframe. It appears as though this occurs for trades that occur in the last hour of a Friday,because (I imagine) data doesn't exist for a Saturday at 12am i.e. Friday 11PM + 1 hour. It works for a trade occurring in the last hour of Monday to Thursday.
Any ideas on how to adjust the algo? Please let me know if anything is unclear.
Thanks
Mike
Try
library(dplyr)
res <- left_join(df2,
df %>%
group_by(hour=as.POSIXct(cut(Time, breaks='hour'))+3600) %>%
summarise(Amount=sum(Amount)),
by=c('Time'='hour'))
res$Amount[is.na(res$Amount)] <- 0
res
# Time Profit Amount
#1 2014-05-16 00:00:00 100 0
#2 2014-05-16 01:00:00 200 0
#3 2014-05-16 02:00:00 250 0
#4 2014-05-16 14:00:00 30 0
#5 2014-05-16 15:00:00 -50 195
#6 2014-05-16 16:00:00 67 147
#7 2014-05-16 23:00:00 -8 0
Or using data.table
library(data.table)
DT <- data.table(df)
DT2 <- data.table(df2)
DT1 <- DT[,list(Amount=sum(Amount)), by=(Time=
as.POSIXct(cut(Time, breaks='hour'))+3600)]
setkey(DT1, Time)
DT1[DT2][is.na(Amount), Amount:=0][]
# Time Amount Profit
#1: 2014-05-16 00:00:00 0 100
#2: 2014-05-16 01:00:00 0 200
#3: 2014-05-16 02:00:00 0 250
#4: 2014-05-16 14:00:00 0 30
#5: 2014-05-16 15:00:00 195 -50
#6: 2014-05-16 16:00:00 147 67
#7: 2014-05-16 23:00:00 0 -8
Update
Based on the weekends info,
indx <- with(df, as.numeric(format(Time, '%H'))==23 &
as.numeric(format(Time, '%S'))>0& format(Time, '%a')=='Fri')
grp <- with(df, as.POSIXct(cut(Time, breaks='hour')))
grp[indx] <- grp[indx] +3600*49
grp[!indx] <- grp[!indx]+3600
df$Time <- grp
df %>%
group_by(Time) %>%
summarise(Amount=sum(Amount)) #in the example dataset, it is just 3 rows
# Time Amount
#1 2014-08-15 23:00:00 11037.78
#2 2014-08-18 00:00:00 13374.72
#3 2014-08-21 00:00:00 133373.00
data
df <- structure(list(Time = structure(c(1400263205, 1400263210, 1400263695,
1400264589, 1400266794, 1400267385, 1400268281, 1400272251), class = c("POSIXct",
"POSIXt"), tzone = ""), Amount = c(10L, 20L, 30L, 51L, 84L, 94L,
53L, 44L)), .Names = c("Time", "Amount"), row.names = c(NA, -8L
), class = "data.frame")
df2 <- structure(list(Time = structure(c(1400212800, 1400216400, 1400220000,
1400263200, 1400266800, 1400270400, 1400295600), class = c("POSIXct",
"POSIXt"), tzone = ""), Profit = c(100L, 200L, 250L, 30L, -50L,
67L, -8L)), .Names = c("Time", "Profit"), row.names = c(NA, -7L
), class = "data.frame")
newdata
df <- structure(list(Time = structure(c(1408158000, 1408334400, 1408593600
), tzone = "", class = c("POSIXct", "POSIXt")), Amount = c(11037.778,
13374.724, 133373)), .Names = c("Time", "Amount"), row.names = c(NA,
-3L), class = "data.frame")