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
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
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
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
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.
5 matches
Mail list logo