Converting data to xts changes the timestamp dataHow to join (merge) data frames (inner, outer, left, right)Drop data frame columns by nameChanging column names of a data frameHow to calculate daily means, medians, from weather variables data collected hourly in R?create timeseries based on start and end dateR date origin for time in secondsARIMA ForecastingExtract day and month from dateHow to create full date column using “Month_Year” character string and join three different data frames ordered by the date column in Ri am preparing time series data for building a rnn
Work requires me to come in early to start computer but wont let me clock in to get paid for it
What is the most expensive material in the world that could be used to create Pun-Pun's lute?
How much of a wave function must reside inside event horizon for it to be consumed by the black hole?
How bug prioritization works in agile projects vs non agile
Creating a chemical industry from a medieval tech level without petroleum
A strange hotel
Contradiction proof for inequality of P and NP?
"The cow" OR "a cow" OR "cows" in this context
How do I reattach a shelf to the wall when it ripped out of the wall?
Is Diceware more secure than a long passphrase?
Can someone publish a story that happened to you?
Can a stored procedure reference the database in which it is stored?
Why do games have consumables?
A Paper Record is What I Hamper
Negative Resistance
Does a large simulator bay have standard public address announcements?
Is there a word for the censored part of a video?
Can I criticise the more senior developers around me for not writing clean code?
Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?
What is the best way to deal with NPC-NPC combat?
Is there metaphorical meaning of "aus der Haft entlassen"?
Is there really no use for MD5 anymore?
Why must Chinese maps be obfuscated?
Extracting Dirichlet series coefficients
Converting data to xts changes the timestamp data
How to join (merge) data frames (inner, outer, left, right)Drop data frame columns by nameChanging column names of a data frameHow to calculate daily means, medians, from weather variables data collected hourly in R?create timeseries based on start and end dateR date origin for time in secondsARIMA ForecastingExtract day and month from dateHow to create full date column using “Month_Year” character string and join three different data frames ordered by the date column in Ri am preparing time series data for building a rnn
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am currently doing research on soil moisture and have to get hourly and daily means from my time series data.
When I convert the dataframe into an xts object, the time series changes and I can't figure out why.
The data in the data frame looks like this:
time MC temp
1 2018-06-27 11:30:00 17.1 15.8
2 2018-06-27 11:45:00 17.0 15.8
3 2018-06-27 12:00:00 17.0 15.8
4 2018-06-27 12:15:00 17.0 15.9
5 2018-06-27 12:30:00 17.2 15.9
6 2018-06-27 12:45:00 17.0 16.0
But when I convert it, the time stamp begins at 2018-01-09 00:00 and proceeds to make 5 min time increments. This is the code I am using:
sm_xts <- xts(sm.data[,2:3], as.Date(sm.data$time))
sm_zoo <- read.zoo(sm.data, index.column = 1)
dat_xts <- as.xts(sm_zoo)
I have already converted the time stamp to a as.POSIXct
class and checked for duplicates in my time series.
> anyDuplicated(sm.data$time)
[1] 0
r time-series xts
add a comment |
I am currently doing research on soil moisture and have to get hourly and daily means from my time series data.
When I convert the dataframe into an xts object, the time series changes and I can't figure out why.
The data in the data frame looks like this:
time MC temp
1 2018-06-27 11:30:00 17.1 15.8
2 2018-06-27 11:45:00 17.0 15.8
3 2018-06-27 12:00:00 17.0 15.8
4 2018-06-27 12:15:00 17.0 15.9
5 2018-06-27 12:30:00 17.2 15.9
6 2018-06-27 12:45:00 17.0 16.0
But when I convert it, the time stamp begins at 2018-01-09 00:00 and proceeds to make 5 min time increments. This is the code I am using:
sm_xts <- xts(sm.data[,2:3], as.Date(sm.data$time))
sm_zoo <- read.zoo(sm.data, index.column = 1)
dat_xts <- as.xts(sm_zoo)
I have already converted the time stamp to a as.POSIXct
class and checked for duplicates in my time series.
> anyDuplicated(sm.data$time)
[1] 0
r time-series xts
add a comment |
I am currently doing research on soil moisture and have to get hourly and daily means from my time series data.
When I convert the dataframe into an xts object, the time series changes and I can't figure out why.
The data in the data frame looks like this:
time MC temp
1 2018-06-27 11:30:00 17.1 15.8
2 2018-06-27 11:45:00 17.0 15.8
3 2018-06-27 12:00:00 17.0 15.8
4 2018-06-27 12:15:00 17.0 15.9
5 2018-06-27 12:30:00 17.2 15.9
6 2018-06-27 12:45:00 17.0 16.0
But when I convert it, the time stamp begins at 2018-01-09 00:00 and proceeds to make 5 min time increments. This is the code I am using:
sm_xts <- xts(sm.data[,2:3], as.Date(sm.data$time))
sm_zoo <- read.zoo(sm.data, index.column = 1)
dat_xts <- as.xts(sm_zoo)
I have already converted the time stamp to a as.POSIXct
class and checked for duplicates in my time series.
> anyDuplicated(sm.data$time)
[1] 0
r time-series xts
I am currently doing research on soil moisture and have to get hourly and daily means from my time series data.
When I convert the dataframe into an xts object, the time series changes and I can't figure out why.
The data in the data frame looks like this:
time MC temp
1 2018-06-27 11:30:00 17.1 15.8
2 2018-06-27 11:45:00 17.0 15.8
3 2018-06-27 12:00:00 17.0 15.8
4 2018-06-27 12:15:00 17.0 15.9
5 2018-06-27 12:30:00 17.2 15.9
6 2018-06-27 12:45:00 17.0 16.0
But when I convert it, the time stamp begins at 2018-01-09 00:00 and proceeds to make 5 min time increments. This is the code I am using:
sm_xts <- xts(sm.data[,2:3], as.Date(sm.data$time))
sm_zoo <- read.zoo(sm.data, index.column = 1)
dat_xts <- as.xts(sm_zoo)
I have already converted the time stamp to a as.POSIXct
class and checked for duplicates in my time series.
> anyDuplicated(sm.data$time)
[1] 0
r time-series xts
r time-series xts
edited Mar 24 at 12:31
Joshua Ulrich
141k23280363
141k23280363
asked Mar 22 at 16:32
Danielle CrawfordDanielle Crawford
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Maybe you have some problems with your initial data input process.
df
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
Now the date and time values are stored in a single variable as a char
str(df$time)
# chr [1:6] "2018-06-27 11:30:00" "2018-06-27 11:45:00" ...
Let's convert it into real date and time so as not to lose time information:
strptime(df$time, "%Y-%m-%d %H:%M:%S")
# [1] "2018-06-27 11:30:00 EEST" "2018-06-27 11:45:00 EEST"
# [3] "2018-06-27 12:00:00 EEST" "2018-06-27 12:15:00 EEST"
# [5] "2018-06-27 12:30:00 EEST" "2018-06-27 12:45:00 EEST"
Seems like it works. The possible problems with timezone are beyond the scope of this answer.
Now let's convert the data frame to xts. In the finished xts, we do not need date and time in the symbolic form. So we exclude the first column.
df2xts <- xts(df[,2:3], order.by=strptime(df$time, "%Y-%m-%d %H:%M:%S"))
df2xts
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304037%2fconverting-data-to-xts-changes-the-timestamp-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Maybe you have some problems with your initial data input process.
df
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
Now the date and time values are stored in a single variable as a char
str(df$time)
# chr [1:6] "2018-06-27 11:30:00" "2018-06-27 11:45:00" ...
Let's convert it into real date and time so as not to lose time information:
strptime(df$time, "%Y-%m-%d %H:%M:%S")
# [1] "2018-06-27 11:30:00 EEST" "2018-06-27 11:45:00 EEST"
# [3] "2018-06-27 12:00:00 EEST" "2018-06-27 12:15:00 EEST"
# [5] "2018-06-27 12:30:00 EEST" "2018-06-27 12:45:00 EEST"
Seems like it works. The possible problems with timezone are beyond the scope of this answer.
Now let's convert the data frame to xts. In the finished xts, we do not need date and time in the symbolic form. So we exclude the first column.
df2xts <- xts(df[,2:3], order.by=strptime(df$time, "%Y-%m-%d %H:%M:%S"))
df2xts
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
add a comment |
Maybe you have some problems with your initial data input process.
df
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
Now the date and time values are stored in a single variable as a char
str(df$time)
# chr [1:6] "2018-06-27 11:30:00" "2018-06-27 11:45:00" ...
Let's convert it into real date and time so as not to lose time information:
strptime(df$time, "%Y-%m-%d %H:%M:%S")
# [1] "2018-06-27 11:30:00 EEST" "2018-06-27 11:45:00 EEST"
# [3] "2018-06-27 12:00:00 EEST" "2018-06-27 12:15:00 EEST"
# [5] "2018-06-27 12:30:00 EEST" "2018-06-27 12:45:00 EEST"
Seems like it works. The possible problems with timezone are beyond the scope of this answer.
Now let's convert the data frame to xts. In the finished xts, we do not need date and time in the symbolic form. So we exclude the first column.
df2xts <- xts(df[,2:3], order.by=strptime(df$time, "%Y-%m-%d %H:%M:%S"))
df2xts
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
add a comment |
Maybe you have some problems with your initial data input process.
df
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
Now the date and time values are stored in a single variable as a char
str(df$time)
# chr [1:6] "2018-06-27 11:30:00" "2018-06-27 11:45:00" ...
Let's convert it into real date and time so as not to lose time information:
strptime(df$time, "%Y-%m-%d %H:%M:%S")
# [1] "2018-06-27 11:30:00 EEST" "2018-06-27 11:45:00 EEST"
# [3] "2018-06-27 12:00:00 EEST" "2018-06-27 12:15:00 EEST"
# [5] "2018-06-27 12:30:00 EEST" "2018-06-27 12:45:00 EEST"
Seems like it works. The possible problems with timezone are beyond the scope of this answer.
Now let's convert the data frame to xts. In the finished xts, we do not need date and time in the symbolic form. So we exclude the first column.
df2xts <- xts(df[,2:3], order.by=strptime(df$time, "%Y-%m-%d %H:%M:%S"))
df2xts
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
Maybe you have some problems with your initial data input process.
df
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
Now the date and time values are stored in a single variable as a char
str(df$time)
# chr [1:6] "2018-06-27 11:30:00" "2018-06-27 11:45:00" ...
Let's convert it into real date and time so as not to lose time information:
strptime(df$time, "%Y-%m-%d %H:%M:%S")
# [1] "2018-06-27 11:30:00 EEST" "2018-06-27 11:45:00 EEST"
# [3] "2018-06-27 12:00:00 EEST" "2018-06-27 12:15:00 EEST"
# [5] "2018-06-27 12:30:00 EEST" "2018-06-27 12:45:00 EEST"
Seems like it works. The possible problems with timezone are beyond the scope of this answer.
Now let's convert the data frame to xts. In the finished xts, we do not need date and time in the symbolic form. So we exclude the first column.
df2xts <- xts(df[,2:3], order.by=strptime(df$time, "%Y-%m-%d %H:%M:%S"))
df2xts
# time MC temp
# 1 2018-06-27 11:30:00 17.1 15.8
# 2 2018-06-27 11:45:00 17.0 15.8
# 3 2018-06-27 12:00:00 17.0 15.8
# 4 2018-06-27 12:15:00 17.0 15.9
# 5 2018-06-27 12:30:00 17.2 15.9
# 6 2018-06-27 12:45:00 17.0 16.0
edited Apr 5 at 21:42
answered Apr 5 at 7:42
user3139228user3139228
265
265
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304037%2fconverting-data-to-xts-changes-the-timestamp-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown