Despite your answer to your question, I will also answer. This is for two reasons:.
- In the question data each day is repeated 6 times and with
by = 0.5
only repeats two.
- There are also the missing hours in your reply.
First of all, I start by creating a vector of dates. I modified your seq/as.Date
to make the increment clearer by = "days"
. The second instruction repeats each day such 6 times.
Note that data
is a base R function, so I called this vector Data
.
Data <- seq(as.Date('2013/01/01', "%Y/%m/%d"), as.Date('2018/05/31', "%Y/%m/%d"), by = "days")
Data <- rep(Data, each = 6)
Second, I create a class vector "character"
with the hours. There is also a function seq.POSIXt
but in this case can not be used because the increments of the hours are not constant, the differences of hours of the question data are 1 3 4 4 6
.
Hora <- c("0:00", "1:00", "4:00", "8:00", "12:00", "18:00")
Hora <- rep(Hora, length.out = length(Data))
Finally, I create a data.frame
with the two vectors in the same column.
dados <- data.frame(Data = as.POSIXct(paste(Data, Hora), format = "%Y-%m-%d %H:%M"))
head(dados, n = 20)
# Data
#1 2013-01-01 00:00:00
#2 2013-01-01 01:00:00
#3 2013-01-01 04:00:00
#4 2013-01-01 08:00:00
#5 2013-01-01 12:00:00
#6 2013-01-01 18:00:00
#7 2013-01-02 00:00:00
#8 2013-01-02 01:00:00
#9 2013-01-02 04:00:00
#10 2013-01-02 08:00:00
#11 2013-01-02 12:00:00
#12 2013-01-02 18:00:00
#13 2013-01-03 00:00:00
#14 2013-01-03 01:00:00
#15 2013-01-03 04:00:00
#16 2013-01-03 08:00:00
#17 2013-01-03 12:00:00
#18 2013-01-03 18:00:00
#19 2013-01-04 00:00:00
#20 2013-01-04 01:00:00
Ever tried to do something? Share with us your code so far.
– Marcus Nunes
I only know how to create the date vector in this way
data <- seq(as.Date('2013/01/01', "%Y/%m/%d"), as.Date('2018/05/31', "%Y/%m/%d"), 1)
. But I don’t know how to determine repetitions.– Andreia Almeida
I got it. There was no attempt that I can change the 1 of the end of the function to fractions of day. Thank you!
– Andreia Almeida
@Andreiaalmeida you can answer your own question! It is a good practice to leave the answer so that others also find in future research.
– Daniel Falbel