FAQ 7.31


On Wed, Jul 3, 2013 at 7:55 AM, André de Boer <rnieuws@gmail.com> wrote:

> Hello,
>
> I have two dataframes:
> dat1<-data.frame(x=c(1.0,1.2,3.2,4.0,5.1),y=c(23,17,12,27,8))
> dat2<-data.frame(x=seq(0,6,by=0.1),y=rep(0,60)))
>
> I want to replace the corresponding rows of dat2 with the ones of dat1.
> I tried:
>
> for(i in 1:nrow(dat1))
> {
>   dat2[dat2$x==dat1[i,1],2]<-dat1[i,2]
> }
>
> But I discovered that not every 5.1 is equal:
>
> > dat2[52,1][1] 5.1> dat1[5,1][1] 5.1> dat2[52,1]==dat1[5,1][1] FALSE
>
>
>
> How to solve this?
>
>
>
> Regards,
>
> André
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@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.
>
>


-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

	[[alternative HTML version deleted]]

