Re: [R] Loop With Dates

2019-09-24 Thread Greg Snow
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

Re: [R] Loop With Dates

2019-09-22 Thread Richard O'Keefe
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

Re: [R] Loop With Dates

2019-09-21 Thread Jim Lemon
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

Re: [R] Loop With Dates

2019-09-20 Thread Rui Barradas
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

Re: [R] Loop With Dates

2019-09-20 Thread Ana PGG
== 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

[R] Loop With Dates

2019-09-20 Thread Phillip Heinrich
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

Re: [R] loop with dates

2008-12-12 Thread Jagat.K.Sheth
> -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

Re: [R] loop with dates

2008-12-12 Thread Gabor Grothendieck
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

Re: [R] loop with dates

2008-12-12 Thread Henrique Dallazuanna
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

[R] loop with dates

2008-12-12 Thread Fernando Bizuet
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