[R] split and subset

From: <partofy_at_inoutbox.com>
Date: Tue, 06 May 2008 08:25:45 -0700

Dear list:

I ask for your help in a simple problem in which I'm not figuring out the solution

My data looks like:
dat<- data.frame(date=c("12/12/1980", "03/11/1994", "15/11/1999", "31/10/2000", "20/03/2007", "05/01/2001"), var1=c("A", "A", "B", "D", "C", "A"), var2=runif(6))

I was wondering if I could split the column "date" in 3 new columns in he data frame corresponding to "day", "month" and "year".

If I decide not to split the date in 3 columns, I'd do:

dat$date<- as.Date(dat$date, "%d/%m/%Y")

Now, how can I subset parts of the dataframe, lets say for a given month and year, something like
subset(dat, date=="1999-11-??")
The "??" is obviously wrong. How should I do this?

Many thanks



R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 06 May 2008 - 15:59:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 06 May 2008 - 17:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive