How to import a dataset that already has time data in R and stop R from converting that time data into...
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am trying to import a dataset in R, which has time data and looks like this.
But, when I try to assign it to time series, the time data is being converted to integers, like this:
# AEP_hourly is the original file name
> names(AEP_hourly)
[1] "Datetime" "AEP_MW"
> hourly_ts <- ts(AEP_hourly)
How do I stop this and tell R that it is time data in first column.
r time-series
add a comment |
I am trying to import a dataset in R, which has time data and looks like this.
But, when I try to assign it to time series, the time data is being converted to integers, like this:
# AEP_hourly is the original file name
> names(AEP_hourly)
[1] "Datetime" "AEP_MW"
> hourly_ts <- ts(AEP_hourly)
How do I stop this and tell R that it is time data in first column.
r time-series
What function are you using to load the csv file? I have usedread.csv
and it works fine.
– TeeKea
Nov 29 '18 at 7:37
> library(readr) > AEP_hourly <- read_csv("AEP_hourly.csv")
– Naveen Kumar
Dec 14 '18 at 5:49
Okay, why do you need to show them as datetime? I mean, for what do you needhourly_ts
? For the plot?
– TeeKea
Dec 14 '18 at 6:55
add a comment |
I am trying to import a dataset in R, which has time data and looks like this.
But, when I try to assign it to time series, the time data is being converted to integers, like this:
# AEP_hourly is the original file name
> names(AEP_hourly)
[1] "Datetime" "AEP_MW"
> hourly_ts <- ts(AEP_hourly)
How do I stop this and tell R that it is time data in first column.
r time-series
I am trying to import a dataset in R, which has time data and looks like this.
But, when I try to assign it to time series, the time data is being converted to integers, like this:
# AEP_hourly is the original file name
> names(AEP_hourly)
[1] "Datetime" "AEP_MW"
> hourly_ts <- ts(AEP_hourly)
How do I stop this and tell R that it is time data in first column.
r time-series
r time-series
edited Dec 11 '18 at 17:03
Naveen Kumar
asked Nov 29 '18 at 6:35
Naveen KumarNaveen Kumar
189
189
What function are you using to load the csv file? I have usedread.csv
and it works fine.
– TeeKea
Nov 29 '18 at 7:37
> library(readr) > AEP_hourly <- read_csv("AEP_hourly.csv")
– Naveen Kumar
Dec 14 '18 at 5:49
Okay, why do you need to show them as datetime? I mean, for what do you needhourly_ts
? For the plot?
– TeeKea
Dec 14 '18 at 6:55
add a comment |
What function are you using to load the csv file? I have usedread.csv
and it works fine.
– TeeKea
Nov 29 '18 at 7:37
> library(readr) > AEP_hourly <- read_csv("AEP_hourly.csv")
– Naveen Kumar
Dec 14 '18 at 5:49
Okay, why do you need to show them as datetime? I mean, for what do you needhourly_ts
? For the plot?
– TeeKea
Dec 14 '18 at 6:55
What function are you using to load the csv file? I have used
read.csv
and it works fine.– TeeKea
Nov 29 '18 at 7:37
What function are you using to load the csv file? I have used
read.csv
and it works fine.– TeeKea
Nov 29 '18 at 7:37
> library(readr) > AEP_hourly <- read_csv("AEP_hourly.csv")
– Naveen Kumar
Dec 14 '18 at 5:49
> library(readr) > AEP_hourly <- read_csv("AEP_hourly.csv")
– Naveen Kumar
Dec 14 '18 at 5:49
Okay, why do you need to show them as datetime? I mean, for what do you need
hourly_ts
? For the plot?– TeeKea
Dec 14 '18 at 6:55
Okay, why do you need to show them as datetime? I mean, for what do you need
hourly_ts
? For the plot?– TeeKea
Dec 14 '18 at 6:55
add a comment |
2 Answers
2
active
oldest
votes
Buddy you are converting datetime column into ts().
therefore it is giving result like this.convert only aep column
your code
hour_data <- ts(hourly[,c('time','AEP_MW')])
instead of above code write like this
hour_data <- ts(hourly$AEP_MW)
as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" That is the error message.
– Naveen Kumar
Nov 29 '18 at 17:35
>hourly <- AEP_hourly > as.date(hourly$Datetime) Error in as.date(hourly$Datetime) : could not find function "as.date" > as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" that is what i got.
– Naveen Kumar
Nov 29 '18 at 17:46
The function isas.POSIXct
, with the lowercasect
– Mako212
Nov 29 '18 at 17:47
1
@Naveen: Yes its as.POSIXct(), and share your code and error message.
– Zeeshan
Nov 30 '18 at 5:07
I've already shared my error message, which is second comment to the answer. see the answer, it had 'POSIXCT' with capital 'CT', which led me to me error. Thanks.
– Naveen Kumar
Nov 30 '18 at 5:47
|
show 4 more comments
I am not sure why you need the time
to be included int ts
object. Using the following:
hour_data <- ts(hourly[,c('AEP_MW')])
will give an output similar to this:
Time Series:
Start = 1
End = 11
Frequency = 1
AEP_MW
[1,] 13478
[2,] 12865
[3,] 12577
[4,] 12517
[5,] 12670
[6,] 13038
[7,] 13692
[8,] 14297
[9,] 14719
[10,] 14941
[11,] 15184
Now, if you plot(hour_data)
this, you would get this:
But I guess you desire to show the time
in the x-axis. You may do so as follows:
plot(hour_data, xaxt = "n", ylab="AEP_MW")
axis(1, at=rownames(hourly), labels=hourly$Datetime)
Which will give you this plot:
Hope this helps.
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%2f53533146%2fhow-to-import-a-dataset-that-already-has-time-data-in-r-and-stop-r-from-converti%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Buddy you are converting datetime column into ts().
therefore it is giving result like this.convert only aep column
your code
hour_data <- ts(hourly[,c('time','AEP_MW')])
instead of above code write like this
hour_data <- ts(hourly$AEP_MW)
as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" That is the error message.
– Naveen Kumar
Nov 29 '18 at 17:35
>hourly <- AEP_hourly > as.date(hourly$Datetime) Error in as.date(hourly$Datetime) : could not find function "as.date" > as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" that is what i got.
– Naveen Kumar
Nov 29 '18 at 17:46
The function isas.POSIXct
, with the lowercasect
– Mako212
Nov 29 '18 at 17:47
1
@Naveen: Yes its as.POSIXct(), and share your code and error message.
– Zeeshan
Nov 30 '18 at 5:07
I've already shared my error message, which is second comment to the answer. see the answer, it had 'POSIXCT' with capital 'CT', which led me to me error. Thanks.
– Naveen Kumar
Nov 30 '18 at 5:47
|
show 4 more comments
Buddy you are converting datetime column into ts().
therefore it is giving result like this.convert only aep column
your code
hour_data <- ts(hourly[,c('time','AEP_MW')])
instead of above code write like this
hour_data <- ts(hourly$AEP_MW)
as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" That is the error message.
– Naveen Kumar
Nov 29 '18 at 17:35
>hourly <- AEP_hourly > as.date(hourly$Datetime) Error in as.date(hourly$Datetime) : could not find function "as.date" > as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" that is what i got.
– Naveen Kumar
Nov 29 '18 at 17:46
The function isas.POSIXct
, with the lowercasect
– Mako212
Nov 29 '18 at 17:47
1
@Naveen: Yes its as.POSIXct(), and share your code and error message.
– Zeeshan
Nov 30 '18 at 5:07
I've already shared my error message, which is second comment to the answer. see the answer, it had 'POSIXCT' with capital 'CT', which led me to me error. Thanks.
– Naveen Kumar
Nov 30 '18 at 5:47
|
show 4 more comments
Buddy you are converting datetime column into ts().
therefore it is giving result like this.convert only aep column
your code
hour_data <- ts(hourly[,c('time','AEP_MW')])
instead of above code write like this
hour_data <- ts(hourly$AEP_MW)
Buddy you are converting datetime column into ts().
therefore it is giving result like this.convert only aep column
your code
hour_data <- ts(hourly[,c('time','AEP_MW')])
instead of above code write like this
hour_data <- ts(hourly$AEP_MW)
edited Dec 4 '18 at 12:35
answered Nov 29 '18 at 9:35
ZeeshanZeeshan
515214
515214
as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" That is the error message.
– Naveen Kumar
Nov 29 '18 at 17:35
>hourly <- AEP_hourly > as.date(hourly$Datetime) Error in as.date(hourly$Datetime) : could not find function "as.date" > as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" that is what i got.
– Naveen Kumar
Nov 29 '18 at 17:46
The function isas.POSIXct
, with the lowercasect
– Mako212
Nov 29 '18 at 17:47
1
@Naveen: Yes its as.POSIXct(), and share your code and error message.
– Zeeshan
Nov 30 '18 at 5:07
I've already shared my error message, which is second comment to the answer. see the answer, it had 'POSIXCT' with capital 'CT', which led me to me error. Thanks.
– Naveen Kumar
Nov 30 '18 at 5:47
|
show 4 more comments
as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" That is the error message.
– Naveen Kumar
Nov 29 '18 at 17:35
>hourly <- AEP_hourly > as.date(hourly$Datetime) Error in as.date(hourly$Datetime) : could not find function "as.date" > as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" that is what i got.
– Naveen Kumar
Nov 29 '18 at 17:46
The function isas.POSIXct
, with the lowercasect
– Mako212
Nov 29 '18 at 17:47
1
@Naveen: Yes its as.POSIXct(), and share your code and error message.
– Zeeshan
Nov 30 '18 at 5:07
I've already shared my error message, which is second comment to the answer. see the answer, it had 'POSIXCT' with capital 'CT', which led me to me error. Thanks.
– Naveen Kumar
Nov 30 '18 at 5:47
as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" That is the error message.
– Naveen Kumar
Nov 29 '18 at 17:35
as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" That is the error message.
– Naveen Kumar
Nov 29 '18 at 17:35
>hourly <- AEP_hourly > as.date(hourly$Datetime) Error in as.date(hourly$Datetime) : could not find function "as.date" > as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" that is what i got.
– Naveen Kumar
Nov 29 '18 at 17:46
>hourly <- AEP_hourly > as.date(hourly$Datetime) Error in as.date(hourly$Datetime) : could not find function "as.date" > as.POSIXCT(hourly$Datetime) Error in as.POSIXCT(hourly$Datetime) : could not find function "as.POSIXCT" that is what i got.
– Naveen Kumar
Nov 29 '18 at 17:46
The function is
as.POSIXct
, with the lowercase ct
– Mako212
Nov 29 '18 at 17:47
The function is
as.POSIXct
, with the lowercase ct
– Mako212
Nov 29 '18 at 17:47
1
1
@Naveen: Yes its as.POSIXct(), and share your code and error message.
– Zeeshan
Nov 30 '18 at 5:07
@Naveen: Yes its as.POSIXct(), and share your code and error message.
– Zeeshan
Nov 30 '18 at 5:07
I've already shared my error message, which is second comment to the answer. see the answer, it had 'POSIXCT' with capital 'CT', which led me to me error. Thanks.
– Naveen Kumar
Nov 30 '18 at 5:47
I've already shared my error message, which is second comment to the answer. see the answer, it had 'POSIXCT' with capital 'CT', which led me to me error. Thanks.
– Naveen Kumar
Nov 30 '18 at 5:47
|
show 4 more comments
I am not sure why you need the time
to be included int ts
object. Using the following:
hour_data <- ts(hourly[,c('AEP_MW')])
will give an output similar to this:
Time Series:
Start = 1
End = 11
Frequency = 1
AEP_MW
[1,] 13478
[2,] 12865
[3,] 12577
[4,] 12517
[5,] 12670
[6,] 13038
[7,] 13692
[8,] 14297
[9,] 14719
[10,] 14941
[11,] 15184
Now, if you plot(hour_data)
this, you would get this:
But I guess you desire to show the time
in the x-axis. You may do so as follows:
plot(hour_data, xaxt = "n", ylab="AEP_MW")
axis(1, at=rownames(hourly), labels=hourly$Datetime)
Which will give you this plot:
Hope this helps.
add a comment |
I am not sure why you need the time
to be included int ts
object. Using the following:
hour_data <- ts(hourly[,c('AEP_MW')])
will give an output similar to this:
Time Series:
Start = 1
End = 11
Frequency = 1
AEP_MW
[1,] 13478
[2,] 12865
[3,] 12577
[4,] 12517
[5,] 12670
[6,] 13038
[7,] 13692
[8,] 14297
[9,] 14719
[10,] 14941
[11,] 15184
Now, if you plot(hour_data)
this, you would get this:
But I guess you desire to show the time
in the x-axis. You may do so as follows:
plot(hour_data, xaxt = "n", ylab="AEP_MW")
axis(1, at=rownames(hourly), labels=hourly$Datetime)
Which will give you this plot:
Hope this helps.
add a comment |
I am not sure why you need the time
to be included int ts
object. Using the following:
hour_data <- ts(hourly[,c('AEP_MW')])
will give an output similar to this:
Time Series:
Start = 1
End = 11
Frequency = 1
AEP_MW
[1,] 13478
[2,] 12865
[3,] 12577
[4,] 12517
[5,] 12670
[6,] 13038
[7,] 13692
[8,] 14297
[9,] 14719
[10,] 14941
[11,] 15184
Now, if you plot(hour_data)
this, you would get this:
But I guess you desire to show the time
in the x-axis. You may do so as follows:
plot(hour_data, xaxt = "n", ylab="AEP_MW")
axis(1, at=rownames(hourly), labels=hourly$Datetime)
Which will give you this plot:
Hope this helps.
I am not sure why you need the time
to be included int ts
object. Using the following:
hour_data <- ts(hourly[,c('AEP_MW')])
will give an output similar to this:
Time Series:
Start = 1
End = 11
Frequency = 1
AEP_MW
[1,] 13478
[2,] 12865
[3,] 12577
[4,] 12517
[5,] 12670
[6,] 13038
[7,] 13692
[8,] 14297
[9,] 14719
[10,] 14941
[11,] 15184
Now, if you plot(hour_data)
this, you would get this:
But I guess you desire to show the time
in the x-axis. You may do so as follows:
plot(hour_data, xaxt = "n", ylab="AEP_MW")
axis(1, at=rownames(hourly), labels=hourly$Datetime)
Which will give you this plot:
Hope this helps.
answered Dec 14 '18 at 7:34
TeeKeaTeeKea
3,25351932
3,25351932
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%2f53533146%2fhow-to-import-a-dataset-that-already-has-time-data-in-r-and-stop-r-from-converti%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
What function are you using to load the csv file? I have used
read.csv
and it works fine.– TeeKea
Nov 29 '18 at 7:37
> library(readr) > AEP_hourly <- read_csv("AEP_hourly.csv")
– Naveen Kumar
Dec 14 '18 at 5:49
Okay, why do you need to show them as datetime? I mean, for what do you need
hourly_ts
? For the plot?– TeeKea
Dec 14 '18 at 6:55