[R] merge two dataset and replace missing by 0

Uwe Ligges ligges at statistik.tu-dortmund.de
Mon Nov 15 17:06:14 CET 2010


See ?merge with argument all=TRUE and replace by 0 afterwards.

Uwe Ligges



On 15.11.2010 16:42, Kate Hsu wrote:
> Hi r users,
>
> I have two data sets (X1, X2). For example,
> time1<-c( 0,   8,  15,  22,  43,  64,  85, 106, 127, 148, 169, 190 ,211 )
> outpue1<-c(171 ,164 ,150 ,141 ,109 , 73 , 47  ,26  ,15  ,12   ,6   ,2   ,1 )
> X1<-cbind(time1,outpue1)
>
> time2<-c( 0   ,8  ,15 , 22  ,43 , 64  ,85 ,106 ,148)
> output2<-c( 5   ,5   ,4   ,5   ,5   ,4   ,1   ,2 ,  1 )
> X2<-cbind(time2,output2)
>
> I want to merge X1 and X2 into a big dataset X by time1 and time2 so that
> the missing item in output2 will be replace by 0. For example, there is no
> output2 when time2=127, then the corresponding output will be 0. Anyone know
> how to use merge command to deal with this?
>
> Thanks,
>
> Kate
>
> 	[[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.



More information about the R-help mailing list