Generate Sequence of Dates and Time for each ID in RCalculate relative time in C#How to get the current time in PythonWhat do 'real', 'user' and 'sys' mean in the output of time(1)?Add days to JavaScript DateConvert a Unix timestamp to time in JavaScriptHow do I get time of a Python program's execution?Java string to date conversionGet current time and date on AndroidFormatting dates and times with as.POSIXct in RR How to convert numerical hour value to %H:%M:%S and add time to a date

What exactly are the `size issues' preventing formation of presheaves being a left adjoint to some forgetful functor?

What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?

Frequency of specific viral sequence in .BAM or .fastq

Is there an idiom that support the idea that "inflation is bad"?

Point of the Dothraki's attack in GoT S8E3?

What does this wavy downward arrow preceding a piano chord mean?

US born but as a child of foreign diplomat

Should I decline this job offer that requires relocating to an area with high cost of living?

How to adjust tikz picture so it fits to current size of a table cell?

What was Bran's plan to kill the Night King?

Something that can be activated/enabled

Wrong answer from DSolve when solving a differential equation

Pressure inside an infinite ocean?

When two pilots are required for a private aircraft, is it a requirement for the PIC to be ATPL?

Is there an official reason for not adding a post-credits scene?

Has the Hulk always been able to talk?

Copy previous line to current line from text file

I need a disease

Would glacier 'trees' be plausible?

Decoupling cap routing on a 4 layer PCB

Does it make sense for a function to return a rvalue reference

Where can I go to avoid planes overhead?

How to write a 12-bar blues melody

Word for Food that's Gone 'Bad', but is Still Edible?



Generate Sequence of Dates and Time for each ID in R


Calculate relative time in C#How to get the current time in PythonWhat do 'real', 'user' and 'sys' mean in the output of time(1)?Add days to JavaScript DateConvert a Unix timestamp to time in JavaScriptHow do I get time of a Python program's execution?Java string to date conversionGet current time and date on AndroidFormatting dates and times with as.POSIXct in RR How to convert numerical hour value to %H:%M:%S and add time to a date






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








1















I'm trying to figure out the way of creating sequence of dates and time in this format: 2018-01-01 01:00 till 2018-03-30 01:00
for each Patient and fill the new empty value with random numbers.



My data look like :



Patients temperature 
Patient1 37
Patient2 36
Patient3 35.4


I want to get the data looks like



Patients temperature Time 
Patient1 37 2018-01-01 01:00
Patient2 36 2018-01-01 01:00
Patient3 35.4 2018-01-01 01:00
Patient1 NA 2018-01-01 02:00
Patient2 NA 2018-01-01 02:00
Patient3 NA 2018-01-01 02:00
Patient1 NA 2018-01-01 03:00
Patient2 NA 2018-01-01 03:00
Patient3 NA 2018-01-01 03:00


So the Time variable will be till 2018-03-30 01:00 and the temperature can be NA and then I generate random numbers but not repeating the same values of the temperature of each Patient.



I tried this commands but didn't work and I don't know how to assign the time to each Patient



Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


And I tried too this command but I got error message:



dt = data.table(ID = Sensor7$StationID,Time = seq (from=as.POSIXct("2018-01-01 02:00"), to=as.POSIXct("2018-03-30 01:00",format = "%Y-%m-%d %H:%M",by="hour")))


But it gave me error message:



Error in seq.POSIXt(from = as.POSIXct("2018-01-01 00:00"), to = as.POSIXct("2018-03-30 23:00", : 
exactly two of 'to', 'by' and 'length.out' / 'along.with' must be specified


Does anyone have any idea how to get the data in the format I'm looking for pleas?










share|improve this question




























    1















    I'm trying to figure out the way of creating sequence of dates and time in this format: 2018-01-01 01:00 till 2018-03-30 01:00
    for each Patient and fill the new empty value with random numbers.



    My data look like :



    Patients temperature 
    Patient1 37
    Patient2 36
    Patient3 35.4


    I want to get the data looks like



    Patients temperature Time 
    Patient1 37 2018-01-01 01:00
    Patient2 36 2018-01-01 01:00
    Patient3 35.4 2018-01-01 01:00
    Patient1 NA 2018-01-01 02:00
    Patient2 NA 2018-01-01 02:00
    Patient3 NA 2018-01-01 02:00
    Patient1 NA 2018-01-01 03:00
    Patient2 NA 2018-01-01 03:00
    Patient3 NA 2018-01-01 03:00


    So the Time variable will be till 2018-03-30 01:00 and the temperature can be NA and then I generate random numbers but not repeating the same values of the temperature of each Patient.



    I tried this commands but didn't work and I don't know how to assign the time to each Patient



    Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


    And I tried too this command but I got error message:



    dt = data.table(ID = Sensor7$StationID,Time = seq (from=as.POSIXct("2018-01-01 02:00"), to=as.POSIXct("2018-03-30 01:00",format = "%Y-%m-%d %H:%M",by="hour")))


    But it gave me error message:



    Error in seq.POSIXt(from = as.POSIXct("2018-01-01 00:00"), to = as.POSIXct("2018-03-30 23:00", : 
    exactly two of 'to', 'by' and 'length.out' / 'along.with' must be specified


    Does anyone have any idea how to get the data in the format I'm looking for pleas?










    share|improve this question
























      1












      1








      1








      I'm trying to figure out the way of creating sequence of dates and time in this format: 2018-01-01 01:00 till 2018-03-30 01:00
      for each Patient and fill the new empty value with random numbers.



      My data look like :



      Patients temperature 
      Patient1 37
      Patient2 36
      Patient3 35.4


      I want to get the data looks like



      Patients temperature Time 
      Patient1 37 2018-01-01 01:00
      Patient2 36 2018-01-01 01:00
      Patient3 35.4 2018-01-01 01:00
      Patient1 NA 2018-01-01 02:00
      Patient2 NA 2018-01-01 02:00
      Patient3 NA 2018-01-01 02:00
      Patient1 NA 2018-01-01 03:00
      Patient2 NA 2018-01-01 03:00
      Patient3 NA 2018-01-01 03:00


      So the Time variable will be till 2018-03-30 01:00 and the temperature can be NA and then I generate random numbers but not repeating the same values of the temperature of each Patient.



      I tried this commands but didn't work and I don't know how to assign the time to each Patient



      Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


      And I tried too this command but I got error message:



      dt = data.table(ID = Sensor7$StationID,Time = seq (from=as.POSIXct("2018-01-01 02:00"), to=as.POSIXct("2018-03-30 01:00",format = "%Y-%m-%d %H:%M",by="hour")))


      But it gave me error message:



      Error in seq.POSIXt(from = as.POSIXct("2018-01-01 00:00"), to = as.POSIXct("2018-03-30 23:00", : 
      exactly two of 'to', 'by' and 'length.out' / 'along.with' must be specified


      Does anyone have any idea how to get the data in the format I'm looking for pleas?










      share|improve this question














      I'm trying to figure out the way of creating sequence of dates and time in this format: 2018-01-01 01:00 till 2018-03-30 01:00
      for each Patient and fill the new empty value with random numbers.



      My data look like :



      Patients temperature 
      Patient1 37
      Patient2 36
      Patient3 35.4


      I want to get the data looks like



      Patients temperature Time 
      Patient1 37 2018-01-01 01:00
      Patient2 36 2018-01-01 01:00
      Patient3 35.4 2018-01-01 01:00
      Patient1 NA 2018-01-01 02:00
      Patient2 NA 2018-01-01 02:00
      Patient3 NA 2018-01-01 02:00
      Patient1 NA 2018-01-01 03:00
      Patient2 NA 2018-01-01 03:00
      Patient3 NA 2018-01-01 03:00


      So the Time variable will be till 2018-03-30 01:00 and the temperature can be NA and then I generate random numbers but not repeating the same values of the temperature of each Patient.



      I tried this commands but didn't work and I don't know how to assign the time to each Patient



      Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


      And I tried too this command but I got error message:



      dt = data.table(ID = Sensor7$StationID,Time = seq (from=as.POSIXct("2018-01-01 02:00"), to=as.POSIXct("2018-03-30 01:00",format = "%Y-%m-%d %H:%M",by="hour")))


      But it gave me error message:



      Error in seq.POSIXt(from = as.POSIXct("2018-01-01 00:00"), to = as.POSIXct("2018-03-30 23:00", : 
      exactly two of 'to', 'by' and 'length.out' / 'along.with' must be specified


      Does anyone have any idea how to get the data in the format I'm looking for pleas?







      r time time-series posixct






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 23:51









      RetaReta

      4918




      4918






















          2 Answers
          2






          active

          oldest

          votes


















          0














          You weren't too far off. Try this:



          # I reproduce your data:

          library(data.table)
          data = data.table::fread(input =
          "Patients,temperature
          Patient1,37
          Patient2,36
          Patient3,35.4")

          library(dplyr)

          Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


          And this should do what you want:



          data %>% 
          group_by(Patients) %>%
          do(data.frame("temperature" = c(.data$temperature, rep(NA,length(Time) - nrow(.data))), Time))






          share|improve this answer























          • Thank you!! this is what I was looking for !! Thank you again

            – Reta
            Mar 23 at 18:09


















          0














          Here's one way:



          dat = data.frame(Patients=paste0("Patients", 1:3), temperature=c(37,36,35.4))

          Time = seq(as.POSIXct("2018-01-01 01:00"), as.POSIXct("2018-03-30 01:00"), by="hour")

          new.data = data.frame(
          Patient = rep(dat$Patients, each=length(Time)),
          Time = rep(Time, length(dat$Patients))
          )


          I'm not sure how you want to generate the random values, but here's a generic method:



          new.data$Random.Temperature = rnorm(nrow(new.data), 35, 1)





          share|improve this answer























          • Thank you so much! it helped

            – Reta
            Mar 23 at 18:09











          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%2f55309198%2fgenerate-sequence-of-dates-and-time-for-each-id-in-r%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














          You weren't too far off. Try this:



          # I reproduce your data:

          library(data.table)
          data = data.table::fread(input =
          "Patients,temperature
          Patient1,37
          Patient2,36
          Patient3,35.4")

          library(dplyr)

          Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


          And this should do what you want:



          data %>% 
          group_by(Patients) %>%
          do(data.frame("temperature" = c(.data$temperature, rep(NA,length(Time) - nrow(.data))), Time))






          share|improve this answer























          • Thank you!! this is what I was looking for !! Thank you again

            – Reta
            Mar 23 at 18:09















          0














          You weren't too far off. Try this:



          # I reproduce your data:

          library(data.table)
          data = data.table::fread(input =
          "Patients,temperature
          Patient1,37
          Patient2,36
          Patient3,35.4")

          library(dplyr)

          Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


          And this should do what you want:



          data %>% 
          group_by(Patients) %>%
          do(data.frame("temperature" = c(.data$temperature, rep(NA,length(Time) - nrow(.data))), Time))






          share|improve this answer























          • Thank you!! this is what I was looking for !! Thank you again

            – Reta
            Mar 23 at 18:09













          0












          0








          0







          You weren't too far off. Try this:



          # I reproduce your data:

          library(data.table)
          data = data.table::fread(input =
          "Patients,temperature
          Patient1,37
          Patient2,36
          Patient3,35.4")

          library(dplyr)

          Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


          And this should do what you want:



          data %>% 
          group_by(Patients) %>%
          do(data.frame("temperature" = c(.data$temperature, rep(NA,length(Time) - nrow(.data))), Time))






          share|improve this answer













          You weren't too far off. Try this:



          # I reproduce your data:

          library(data.table)
          data = data.table::fread(input =
          "Patients,temperature
          Patient1,37
          Patient2,36
          Patient3,35.4")

          library(dplyr)

          Time <- seq (from=as.POSIXct("2018-1-1 01:00"), to=as.POSIXct("2018-3-30 01:00", tz="UTC"), by="hour")


          And this should do what you want:



          data %>% 
          group_by(Patients) %>%
          do(data.frame("temperature" = c(.data$temperature, rep(NA,length(Time) - nrow(.data))), Time))







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 0:32









          Armando RoblesArmando Robles

          162




          162












          • Thank you!! this is what I was looking for !! Thank you again

            – Reta
            Mar 23 at 18:09

















          • Thank you!! this is what I was looking for !! Thank you again

            – Reta
            Mar 23 at 18:09
















          Thank you!! this is what I was looking for !! Thank you again

          – Reta
          Mar 23 at 18:09





          Thank you!! this is what I was looking for !! Thank you again

          – Reta
          Mar 23 at 18:09













          0














          Here's one way:



          dat = data.frame(Patients=paste0("Patients", 1:3), temperature=c(37,36,35.4))

          Time = seq(as.POSIXct("2018-01-01 01:00"), as.POSIXct("2018-03-30 01:00"), by="hour")

          new.data = data.frame(
          Patient = rep(dat$Patients, each=length(Time)),
          Time = rep(Time, length(dat$Patients))
          )


          I'm not sure how you want to generate the random values, but here's a generic method:



          new.data$Random.Temperature = rnorm(nrow(new.data), 35, 1)





          share|improve this answer























          • Thank you so much! it helped

            – Reta
            Mar 23 at 18:09















          0














          Here's one way:



          dat = data.frame(Patients=paste0("Patients", 1:3), temperature=c(37,36,35.4))

          Time = seq(as.POSIXct("2018-01-01 01:00"), as.POSIXct("2018-03-30 01:00"), by="hour")

          new.data = data.frame(
          Patient = rep(dat$Patients, each=length(Time)),
          Time = rep(Time, length(dat$Patients))
          )


          I'm not sure how you want to generate the random values, but here's a generic method:



          new.data$Random.Temperature = rnorm(nrow(new.data), 35, 1)





          share|improve this answer























          • Thank you so much! it helped

            – Reta
            Mar 23 at 18:09













          0












          0








          0







          Here's one way:



          dat = data.frame(Patients=paste0("Patients", 1:3), temperature=c(37,36,35.4))

          Time = seq(as.POSIXct("2018-01-01 01:00"), as.POSIXct("2018-03-30 01:00"), by="hour")

          new.data = data.frame(
          Patient = rep(dat$Patients, each=length(Time)),
          Time = rep(Time, length(dat$Patients))
          )


          I'm not sure how you want to generate the random values, but here's a generic method:



          new.data$Random.Temperature = rnorm(nrow(new.data), 35, 1)





          share|improve this answer













          Here's one way:



          dat = data.frame(Patients=paste0("Patients", 1:3), temperature=c(37,36,35.4))

          Time = seq(as.POSIXct("2018-01-01 01:00"), as.POSIXct("2018-03-30 01:00"), by="hour")

          new.data = data.frame(
          Patient = rep(dat$Patients, each=length(Time)),
          Time = rep(Time, length(dat$Patients))
          )


          I'm not sure how you want to generate the random values, but here's a generic method:



          new.data$Random.Temperature = rnorm(nrow(new.data), 35, 1)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 0:03









          eipi10eipi10

          61.1k16111169




          61.1k16111169












          • Thank you so much! it helped

            – Reta
            Mar 23 at 18:09

















          • Thank you so much! it helped

            – Reta
            Mar 23 at 18:09
















          Thank you so much! it helped

          – Reta
          Mar 23 at 18:09





          Thank you so much! it helped

          – Reta
          Mar 23 at 18:09

















          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%2f55309198%2fgenerate-sequence-of-dates-and-time-for-each-id-in-r%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현