Re: [R] Update a variable in a dataframe based on variables in another dataframe of a different size

2013-11-13 Thread arun
Hi Don, In cases like: H_DF <- H_DF[-4,] tmp1 <- match( paste(T_DF$FY,T_DF$ID) , paste(H_DF$FY,H_DF$ID) )  H_DF$TT[tmp1] <- T_DF$TT #Error in `[<-.factor`(`*tmp*`, tmp1, value = c(2L, 2L, 2L)) : Probably, this works: H_DF$TT[tmp1[!is.na(tmp1)]] <- unique(T_DF$TT) A.K. On Wednesday, Novemb

Re: [R] Update a variable in a dataframe based on variables in another dataframe of a different size

2013-11-13 Thread MacQueen, Don
Dan, Gabor's solution is of course good, but here's a solution that uses only base R capabilities, and doesn't sort as merge() does. Essentially the same as A.K.'s, but slightly more general. tmp1 <- match( paste(T_DF$FY,T_DF$ID) , paste(H_DF$FY,H_DF$ID) ) H_DF$TT[tmp1] <- T_DF$TT gg <- sqldf("s

Re: [R] Update a variable in a dataframe based on variables in another dataframe of a different size

2013-11-13 Thread Lopez, Dan
This is a great solution! Love the conciseness of your solution. And easy to understand. Thanks again. Dan -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: Monday, November 11, 2013 6:31 PM To: Lopez, Dan Subject: Re: [R] Update a variable in a dataframe based on

Re: [R] Update a variable in a dataframe based on variables in another dataframe of a different size

2013-11-11 Thread Gabor Grothendieck
On Mon, Nov 11, 2013 at 8:04 PM, Lopez, Dan wrote: > Below is how I am currently doing this. Is there a more efficient way to do > this? > The scenario is that I have two dataframes of different sizes. I need to > update one binary factor variable in one of those dataframes by matching on > two

[R] Update a variable in a dataframe based on variables in another dataframe of a different size

2013-11-11 Thread Lopez, Dan
Below is how I am currently doing this. Is there a more efficient way to do this? The scenario is that I have two dataframes of different sizes. I need to update one binary factor variable in one of those dataframes by matching on two variables. If there is no match keep as is otherwise update.