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 Livermo
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 4",
> header=TRUE)
>
>
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) {
time2<-which(df2$
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( d
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 t
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 4
6 matches
Mail list logo