[R] finding the row(s) for a date in a data frame
helprhelp at gmail.com
Sat Aug 18 00:17:19 CEST 2007
try this, and you will get a clue:
> (today <- Sys.Date())
> as.Date("2007-08-17") == today
your.target = as.Date("1979-12-14")
apply(A, c(1,2), function(x) x==your.target)) # should work. I did not
On 8/17/07, Gonçalo Ferraz <gferraz29 at gmail.com> wrote:
> If I have a data frame A with the following format:
> Day1 Day2 Day3 Day4
> 1 1979-11-02 1979-11-03 1979-11-04 <NA>
> 2 1979-12-06 <NA> <NA> <NA>
> 3 1979-12-13 1979-12-14 1979-12-15 1979-12-16
> 4 1979-12-20 <NA> <NA> <NA>
> And a date "1979-12-14", for example.
> How can I find the row or rows of the data frame were that date can be
> The date is stored in a date format variable called 'day'. I am trying
> commands such as A==day, expecting to see a matrix of logical values, but I
> am only getting error messages such as "(list) object cannot be coerced to
> I am looking for a simple command that would return, in this case, a vector:
> FALSE FALSE TRUE FALSE
> Thanks for any help!
> [[alternative HTML version deleted]]
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Weiwei Shi, Ph.D
"Did you always know?"
"No, I did not. But I believed..."
More information about the R-help