R Extract time from timestamp then save as a new column





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















Please can someone advise where i am going wrong. I have the code below to extract hour, minutes, and seconds. It doesn't work. I am getting an error message:




Error in UseMethod("mutate_") : no applicable method for 'mutate_'
applied to an object of class "function"




lubridate::ymd_hms(as.character(d1$timestamp, tz = "UTC"))

df %>% mutate(hours=hour(strptime(d1$timestamp, %H:%M')) %>%
as.character() )









share|improve this question

























  • can you please show an example of the actual data?

    – nick
    Jan 4 at 15:12


















0















Please can someone advise where i am going wrong. I have the code below to extract hour, minutes, and seconds. It doesn't work. I am getting an error message:




Error in UseMethod("mutate_") : no applicable method for 'mutate_'
applied to an object of class "function"




lubridate::ymd_hms(as.character(d1$timestamp, tz = "UTC"))

df %>% mutate(hours=hour(strptime(d1$timestamp, %H:%M')) %>%
as.character() )









share|improve this question

























  • can you please show an example of the actual data?

    – nick
    Jan 4 at 15:12














0












0








0








Please can someone advise where i am going wrong. I have the code below to extract hour, minutes, and seconds. It doesn't work. I am getting an error message:




Error in UseMethod("mutate_") : no applicable method for 'mutate_'
applied to an object of class "function"




lubridate::ymd_hms(as.character(d1$timestamp, tz = "UTC"))

df %>% mutate(hours=hour(strptime(d1$timestamp, %H:%M')) %>%
as.character() )









share|improve this question
















Please can someone advise where i am going wrong. I have the code below to extract hour, minutes, and seconds. It doesn't work. I am getting an error message:




Error in UseMethod("mutate_") : no applicable method for 'mutate_'
applied to an object of class "function"




lubridate::ymd_hms(as.character(d1$timestamp, tz = "UTC"))

df %>% mutate(hours=hour(strptime(d1$timestamp, %H:%M')) %>%
as.character() )






r






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 15:22









nick

6881619




6881619










asked Jan 4 at 15:02









user5576922user5576922

114




114













  • can you please show an example of the actual data?

    – nick
    Jan 4 at 15:12



















  • can you please show an example of the actual data?

    – nick
    Jan 4 at 15:12

















can you please show an example of the actual data?

– nick
Jan 4 at 15:12





can you please show an example of the actual data?

– nick
Jan 4 at 15:12












2 Answers
2






active

oldest

votes


















0














Maybe this can help:



# some fake data
df <- data.frame(a = 1, timestamp = '2018-11-11 12:13:14')

# convert as data
library(lubridate)
df$timestamp <- ymd_hms(as.character(df$timestamp, tz = "UTC"))

# add the hour:minutes column
library(dplyr)
df %>% mutate(hour_ = format(df$timestamp,'%H:%M'))
a timestamp hour_
1 1 2018-11-11 12:13:14 12:13


Or in only one dplyr chain:



df %>%
mutate(hour_ = format(ymd_hms(as.character(df$timestamp, tz = "UTC")),'%H:%M'))





share|improve this answer
























  • @user5576922 you are welcome, if you share the data that creates the problem, posting a part of them editing the question, it's going to be easier to help.

    – s_t
    Jan 4 at 15:22













  • How do i define a data frame instead of a specific date, please?

    – user5576922
    Jan 4 at 15:26











  • d1 conatins my data as a data frame

    – user5576922
    Jan 4 at 15:27











  • Could you share the output of dput(head(d1,5)) editing the question? This line is going to print something like structure(.... . They are the first 5 rows of your dataset. Post them editing the question, it's going to be easier and faster to help you having it.

    – s_t
    Jan 4 at 15:29











  • Thanks again for your help. I am sorted now.

    – user5576922
    Jan 5 at 10:58



















0














I would check (try this function) if the package using that function is actually loaded - and in the right order.

If you're calling mutate from dplyr try dplyr::mutate instead of just mutate. If that works than it may just be that you have to check if a similar named function from another package is loaded after dplyr and change the order in which you load them if that is a suitable option.






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%2f54041444%2fr-extract-time-from-timestamp-then-save-as-a-new-column%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









    0














    Maybe this can help:



    # some fake data
    df <- data.frame(a = 1, timestamp = '2018-11-11 12:13:14')

    # convert as data
    library(lubridate)
    df$timestamp <- ymd_hms(as.character(df$timestamp, tz = "UTC"))

    # add the hour:minutes column
    library(dplyr)
    df %>% mutate(hour_ = format(df$timestamp,'%H:%M'))
    a timestamp hour_
    1 1 2018-11-11 12:13:14 12:13


    Or in only one dplyr chain:



    df %>%
    mutate(hour_ = format(ymd_hms(as.character(df$timestamp, tz = "UTC")),'%H:%M'))





    share|improve this answer
























    • @user5576922 you are welcome, if you share the data that creates the problem, posting a part of them editing the question, it's going to be easier to help.

      – s_t
      Jan 4 at 15:22













    • How do i define a data frame instead of a specific date, please?

      – user5576922
      Jan 4 at 15:26











    • d1 conatins my data as a data frame

      – user5576922
      Jan 4 at 15:27











    • Could you share the output of dput(head(d1,5)) editing the question? This line is going to print something like structure(.... . They are the first 5 rows of your dataset. Post them editing the question, it's going to be easier and faster to help you having it.

      – s_t
      Jan 4 at 15:29











    • Thanks again for your help. I am sorted now.

      – user5576922
      Jan 5 at 10:58
















    0














    Maybe this can help:



    # some fake data
    df <- data.frame(a = 1, timestamp = '2018-11-11 12:13:14')

    # convert as data
    library(lubridate)
    df$timestamp <- ymd_hms(as.character(df$timestamp, tz = "UTC"))

    # add the hour:minutes column
    library(dplyr)
    df %>% mutate(hour_ = format(df$timestamp,'%H:%M'))
    a timestamp hour_
    1 1 2018-11-11 12:13:14 12:13


    Or in only one dplyr chain:



    df %>%
    mutate(hour_ = format(ymd_hms(as.character(df$timestamp, tz = "UTC")),'%H:%M'))





    share|improve this answer
























    • @user5576922 you are welcome, if you share the data that creates the problem, posting a part of them editing the question, it's going to be easier to help.

      – s_t
      Jan 4 at 15:22













    • How do i define a data frame instead of a specific date, please?

      – user5576922
      Jan 4 at 15:26











    • d1 conatins my data as a data frame

      – user5576922
      Jan 4 at 15:27











    • Could you share the output of dput(head(d1,5)) editing the question? This line is going to print something like structure(.... . They are the first 5 rows of your dataset. Post them editing the question, it's going to be easier and faster to help you having it.

      – s_t
      Jan 4 at 15:29











    • Thanks again for your help. I am sorted now.

      – user5576922
      Jan 5 at 10:58














    0












    0








    0







    Maybe this can help:



    # some fake data
    df <- data.frame(a = 1, timestamp = '2018-11-11 12:13:14')

    # convert as data
    library(lubridate)
    df$timestamp <- ymd_hms(as.character(df$timestamp, tz = "UTC"))

    # add the hour:minutes column
    library(dplyr)
    df %>% mutate(hour_ = format(df$timestamp,'%H:%M'))
    a timestamp hour_
    1 1 2018-11-11 12:13:14 12:13


    Or in only one dplyr chain:



    df %>%
    mutate(hour_ = format(ymd_hms(as.character(df$timestamp, tz = "UTC")),'%H:%M'))





    share|improve this answer













    Maybe this can help:



    # some fake data
    df <- data.frame(a = 1, timestamp = '2018-11-11 12:13:14')

    # convert as data
    library(lubridate)
    df$timestamp <- ymd_hms(as.character(df$timestamp, tz = "UTC"))

    # add the hour:minutes column
    library(dplyr)
    df %>% mutate(hour_ = format(df$timestamp,'%H:%M'))
    a timestamp hour_
    1 1 2018-11-11 12:13:14 12:13


    Or in only one dplyr chain:



    df %>%
    mutate(hour_ = format(ymd_hms(as.character(df$timestamp, tz = "UTC")),'%H:%M'))






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 4 at 15:15









    s_ts_t

    3,74121133




    3,74121133













    • @user5576922 you are welcome, if you share the data that creates the problem, posting a part of them editing the question, it's going to be easier to help.

      – s_t
      Jan 4 at 15:22













    • How do i define a data frame instead of a specific date, please?

      – user5576922
      Jan 4 at 15:26











    • d1 conatins my data as a data frame

      – user5576922
      Jan 4 at 15:27











    • Could you share the output of dput(head(d1,5)) editing the question? This line is going to print something like structure(.... . They are the first 5 rows of your dataset. Post them editing the question, it's going to be easier and faster to help you having it.

      – s_t
      Jan 4 at 15:29











    • Thanks again for your help. I am sorted now.

      – user5576922
      Jan 5 at 10:58



















    • @user5576922 you are welcome, if you share the data that creates the problem, posting a part of them editing the question, it's going to be easier to help.

      – s_t
      Jan 4 at 15:22













    • How do i define a data frame instead of a specific date, please?

      – user5576922
      Jan 4 at 15:26











    • d1 conatins my data as a data frame

      – user5576922
      Jan 4 at 15:27











    • Could you share the output of dput(head(d1,5)) editing the question? This line is going to print something like structure(.... . They are the first 5 rows of your dataset. Post them editing the question, it's going to be easier and faster to help you having it.

      – s_t
      Jan 4 at 15:29











    • Thanks again for your help. I am sorted now.

      – user5576922
      Jan 5 at 10:58

















    @user5576922 you are welcome, if you share the data that creates the problem, posting a part of them editing the question, it's going to be easier to help.

    – s_t
    Jan 4 at 15:22







    @user5576922 you are welcome, if you share the data that creates the problem, posting a part of them editing the question, it's going to be easier to help.

    – s_t
    Jan 4 at 15:22















    How do i define a data frame instead of a specific date, please?

    – user5576922
    Jan 4 at 15:26





    How do i define a data frame instead of a specific date, please?

    – user5576922
    Jan 4 at 15:26













    d1 conatins my data as a data frame

    – user5576922
    Jan 4 at 15:27





    d1 conatins my data as a data frame

    – user5576922
    Jan 4 at 15:27













    Could you share the output of dput(head(d1,5)) editing the question? This line is going to print something like structure(.... . They are the first 5 rows of your dataset. Post them editing the question, it's going to be easier and faster to help you having it.

    – s_t
    Jan 4 at 15:29





    Could you share the output of dput(head(d1,5)) editing the question? This line is going to print something like structure(.... . They are the first 5 rows of your dataset. Post them editing the question, it's going to be easier and faster to help you having it.

    – s_t
    Jan 4 at 15:29













    Thanks again for your help. I am sorted now.

    – user5576922
    Jan 5 at 10:58





    Thanks again for your help. I am sorted now.

    – user5576922
    Jan 5 at 10:58













    0














    I would check (try this function) if the package using that function is actually loaded - and in the right order.

    If you're calling mutate from dplyr try dplyr::mutate instead of just mutate. If that works than it may just be that you have to check if a similar named function from another package is loaded after dplyr and change the order in which you load them if that is a suitable option.






    share|improve this answer






























      0














      I would check (try this function) if the package using that function is actually loaded - and in the right order.

      If you're calling mutate from dplyr try dplyr::mutate instead of just mutate. If that works than it may just be that you have to check if a similar named function from another package is loaded after dplyr and change the order in which you load them if that is a suitable option.






      share|improve this answer




























        0












        0








        0







        I would check (try this function) if the package using that function is actually loaded - and in the right order.

        If you're calling mutate from dplyr try dplyr::mutate instead of just mutate. If that works than it may just be that you have to check if a similar named function from another package is loaded after dplyr and change the order in which you load them if that is a suitable option.






        share|improve this answer















        I would check (try this function) if the package using that function is actually loaded - and in the right order.

        If you're calling mutate from dplyr try dplyr::mutate instead of just mutate. If that works than it may just be that you have to check if a similar named function from another package is loaded after dplyr and change the order in which you load them if that is a suitable option.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 4 at 15:18

























        answered Jan 4 at 15:09









        Marc0Marc0

        1116




        1116






























            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%2f54041444%2fr-extract-time-from-timestamp-then-save-as-a-new-column%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

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas