Just to add one more option (which is best probably depends on if all
the same dates are together in adjacent rows, if an earlier date can
come later in the data frame, and other things):
df$count <- cumsum(!duplicated(df$Date))
Skill a cumsum of logicals, just a different way of getting the logi
Is this what you're after?
> df <- data.frame(
+ Date = as.Date(c("2018-03-29", "2018-03-29", "2018-03-29",
+ "2018-03-30", "2018-03-30", "2018- ..." ...
[TRUNCATED]
> df$count <- cumsum(c(TRUE, diff(df$Date) > 0))
> df
Date count
1 2018-03-29 1
2 2018
Hi Phillip,
While I really like Ana's solution, this might also help:
phdf<-read.table(text="Date count
2018-03-29 1
2018-03-29 1
2018-03-29 1
2018-03-30 1
2018-03-30 1
2018-03-30 1
2018-03-31 1
2018-03-31 1
2018-03-31 1",
header=TRUE,strings
Hello,
Maybe I am not understanding but isn't this what you have asked in your
previous question and my 2nd post (adapted) does?
If not, where does it fail?
Hope this helps,
Rui Barradas
Às 18:46 de 20/09/19, Phillip Heinrich escreveu:
With the data snippet below I’m trying to increment the
== dates$lag)) + 1
dates$lag <- NULL
> dates
dates.object count
1 2018-03-29 1
2 2018-03-29 1
3 2018-03-29 1
4 2018-03-30 2
5 2018-03-30 2
6 2018-03-30 2
7 2018-03-31 3
8 2018-03-31 3
9 2018-03-31 3
De: Phillip Heinrich
Enviado: vierne
With the data snippet below I’m trying to increment the “count” vector by one
each time the date changes.
Date count
1 2018-03-29 1
2 2018-03-29 1
3 2018-03-29 1
81 2018-03-30 1
82 2018-03-30 1
83 2018-03-30 1
165 2018-03-31 1
166 2018-03-31 1
1
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Fernando Bizuet
> Sent: Friday, December 12, 2008 12:55 PM
> To: r-help@r-project.org
> Subject: [R] loop with dates
>
> Hello,
>
> I am tryin
Try iterating over the index rather than the value of
each component:
s <- seq(fini,to = ffin, by='days')
for (i in seq_along(s)) print(s[[i]])
On Fri, Dec 12, 2008 at 1:55 PM, Fernando Bizuet wrote:
> Hello,
>
> I am trying to do a loop with dates, but when I try to use the index is not
> a da
Try this:
weekdays(seq(fini,to = ffin, by='days'))
or in a loop:
sapply(as.character(seq(fini,to = ffin, by='days')),
function(d)weekdays(as.Date(d)))
On Fri, Dec 12, 2008 at 4:55 PM, Fernando Bizuet wrote:
> Hello,
>
> I am trying to do a loop with dates, but when I try to use the inde
Hello,
I am trying to do a loop with dates, but when I try to use the index is not
a date.
Fcorte <- as.Date('2008/11/30',format = "%Y/%m/%d")
fini <- Fcorte + 1
ffin <- seq(fini,by='months',length=2)[2] - 1
for (i in seq(fini,to = ffin, by='days'))
print (weekdays(i)) # i does
10 matches
Mail list logo