Re: [R] Query - Merging and conditional replacement of values in a data frame

2017-02-13 Thread MacQueen, Don
How about this? foo <- merge(df1, df2, all=TRUE) is.new <- !is.na(foo$v11) foo$v1[is.new] <- foo$v11[is.new] foo <- foo[, names(df1)] > foo time v1 v2 v3 11 2 3 4 22 5 6 4 33 112 3 4 44 112 3 4 55 2 3 4 66 2 3 4 -- Don MacQueen Lawrence

Re: [R] Query - Merging and conditional replacement of values in a data frame

2017-02-12 Thread Bhaskar Mitra
Thanks for all your help. This is helpful. Best, Bhaskar On Sun, Feb 12, 2017 at 4:35 AM, Jim Lemon wrote: > Hi Bhaskar, > Maybe: > > df1 <-read.table(text="time v1 v2 v3 > 1 2 3 4 > 2 5 6 4 > 3 1 3 4 > 4 1 3 4 > 5 2 3 4 > 6 2 3

Re: [R] Query - Merging and conditional replacement of values in a data frame

2017-02-12 Thread Jim Lemon
Hi Bhaskar, Maybe: df1 <-read.table(text="time v1 v2 v3 1 2 3 4 2 5 6 4 3 1 3 4 4 1 3 4 5 2 3 4 6 2 3 4", header=TRUE) df2 <-read.table(text="time v11 v12 v13 3 112 3 4 4 112 3 4", header=TRUE) for(time1 in df1$time) {

Re: [R] Query - Merging and conditional replacement of values in a data frame

2017-02-11 Thread Jeff Newmiller
Or use rownames and subscripting? df1 <- read.table( text= "time v1 v2 v3 1 2 3 4 2 5 6 4 3 1 3 4 4 1 3 4 5 2 3 4 6 2 3 4 ",header=TRUE) df2 <- read.table( text= "time v11 v12 v13 3 112 3 4 4 112 3 4 ",header=TRUE) df3 <- df1 rownames(

Re: [R] Query - Merging and conditional replacement of values in a data frame

2017-02-11 Thread Bert Gunter
Your "assignments" (<-) are not legitimate R code that can be cut and pasted. Learn to use dput() to provide examples that we can use. You fail to say whether the time column of df2 is a proper subset of df1 or may contain times not in df1. I shall assume the latter. You also did not say whether

[R] Query - Merging and conditional replacement of values in a data frame

2017-02-11 Thread Bhaskar Mitra
Hello Everyone, I have two data frames df1 and df2 as shown below. They are of different length. However, they have one common column - time. df1 <- time v1 v2 v3 1 2 3 4 2 5 6 4 3 1 3 4 4 1 3 4 5 2 3 4 6 2 3 4 df2 <- time v11 v12 v13 3 112 3