Re: [R] How can we creat conditional data frame

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Fri, 04 Apr 2008 09:24:47 -0300

If I understand:

res <- merge(date, da, by.x = "ab", by.y="d", all=T)

res$h <- 0
res$h[is.na(res$r)] <- 1
res$r[is.na(res$r)] <- 0


On Fri, Apr 4, 2008 at 8:49 AM, saikat sarkar <dipa_sanyal_at_yahoo.com> wrote:

>
> Hi,
>
> R experts. I am a new user of R and trying to learn this program.
>
> I have a problem. Here is the code.
>
> d<-as.Date(c("2000/01/03","2000/01/05","2000/01/19","2000/01/28"))
> r<-rnorm(4)
> da<-data.frame(d,r)
>
> a<-as.Date("01/01/2000","%d/%m/%Y")
> b<-as.Date("30/01/2000","%d/%m/%Y")
> ab<-seq(a,b,by=1)
> c<-format(ab,"%a")
> date<-data.frame(ab,c)
> date<-subset(date,c!="Sun")
> date<-subset(date,c!="Sat")
>
> Here I have 2 data frame.
>
> da
> -------------
> d r
> 1 2000-01-03 1.2105865
> 2 2000-01-05 -0.8962776
> 3 2000-01-19 -1.0438936
> 4 2000-01-28 2.1329387
>
> ---------------------------
> date
> --------------
> ab c
> 3 2000-01-03 Mon
> 4 2000-01-04 Tue
> 5 2000-01-05 Wed
> 6 2000-01-06 Thu
> 7 2000-01-07 Fri
> 10 2000-01-10 Mon
> 11 2000-01-11 Tue
> 12 2000-01-12 Wed
> 13 2000-01-13 Thu
> 14 2000-01-14 Fri
> 17 2000-01-17 Mon
> 18 2000-01-18 Tue
> 19 2000-01-19 Wed
> 20 2000-01-20 Thu
> 21 2000-01-21 Fri
> 24 2000-01-24 Mon
> 25 2000-01-25 Tue
> 26 2000-01-26 Wed
> 27 2000-01-27 Thu
> 28 2000-01-28 Fri
>
> ---------------
>
> In data frame-"DA"- I have return(r) and date
> In data frame-"Date"- where I have date and day.
>
> Now I need to create a data frame where returns will be conditional on
> date
> and rest will be zero.
>
> -------------------
> like this
> ---------------------
>
> ab c r hd
> 3 2000-01-03 Mon 1.2105865 0
> 4 2000-01-04 Tue 0 1
> 5 2000-01-05 Wed 0 1
> 6 2000-01-06 Thu 0 1
> 7 2000-01-07 Fri 0 1
>
> ---------------------------------
>
> >From this I can figureout the hoildays and then put each holidays equal
> to
> 1.
>
>
> Please help me.
>
> Thanking you
>
> saikat
>
>
>
> --
> View this message in context:
> http://www.nabble.com/How-can-we-creat-conditional-data-frame-tp16491208p16491208.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


______________________________________________ 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 Fri 04 Apr 2008 - 12:31:11 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 Fri 04 Apr 2008 - 13:30:25 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