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;
}







1















I am trying to import a dataset in R, which has time data and looks like this.



this is original file with time data



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)


The time data being converted to numeric



How do I stop this and tell R that it is time data in first column.










share|improve this question

























  • 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




















1















I am trying to import a dataset in R, which has time data and looks like this.



this is original file with time data



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)


The time data being converted to numeric



How do I stop this and tell R that it is time data in first column.










share|improve this question

























  • 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
















1












1








1








I am trying to import a dataset in R, which has time data and looks like this.



this is original file with time data



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)


The time data being converted to numeric



How do I stop this and tell R that it is time data in first column.










share|improve this question
















I am trying to import a dataset in R, which has time data and looks like this.



this is original file with time data



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)


The time data being converted to numeric



How do I stop this and tell R that it is time data in first column.







r time-series






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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





















  • 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



















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














2 Answers
2






active

oldest

votes


















1














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) 





share|improve this answer


























  • 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 is as.POSIXct, with the lowercase ct

    – 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



















0














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:



enter image description here



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:



enter image description here



Hope this helps.






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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) 





    share|improve this answer


























    • 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 is as.POSIXct, with the lowercase ct

      – 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
















    1














    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) 





    share|improve this answer


























    • 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 is as.POSIXct, with the lowercase ct

      – 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














    1












    1








    1







    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) 





    share|improve this answer















    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) 






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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 is as.POSIXct, with the lowercase ct

      – 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













    • >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






    • 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













    0














    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:



    enter image description here



    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:



    enter image description here



    Hope this helps.






    share|improve this answer




























      0














      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:



      enter image description here



      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:



      enter image description here



      Hope this helps.






      share|improve this answer


























        0












        0








        0







        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:



        enter image description here



        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:



        enter image description here



        Hope this helps.






        share|improve this answer













        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:



        enter image description here



        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:



        enter image description here



        Hope this helps.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 14 '18 at 7:34









        TeeKeaTeeKea

        3,25351932




        3,25351932






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            Idjassú

            count number of partitions of a set with n elements into k subsets