You might need to implement it as a nested pair of for loops using rbind.
In essence iterate over the rows in df1 and each time find the matching
row in df2. If none is found then add the df1 row by itself to the
result. If one is then remove it from df2 and rbind both of them. Once
done just me
Dear all,
I would like to merge two dataframes using two conditions. For example, if
I have the dataframes df1 and df2:
> (df1 <- data.frame(var1=c("a","b","d","e","g"), var2=c(25,14,53,26,84),
infodf1=c(1,1,1,1,1)))
var1 var2 infodf1
1a 25 1
2b 14 1
3d 53 1
So when I do the merge on your example frames, I get the expected result.
But the example component dataframes you sent are already full of NAs, and
there are no rows which are present in both data sets. So I think perhaps, that
merge is just highlighting a problem that has its roots in your com
>
> Re: [R] merging two dataframes
>
> I pasted wrong function, I have changed from "date1" to "date" (ignore
that).
> I think it have to be something wrong with my data format. I can`t
> understand why it don't work. I know I can use by.x= and by.
I pasted wrong function, I have changed from "date1" to "date" (ignore that).
I think it have to be something wrong with my data format. I can`t
understand why it don't work. I know I can use by.x= and by.y=, but
since both datasets have the same variable name it should be unnecessary to
do
>
> Hello.
>
> Now i tried to do what you told me.
> I used the str(fuction), and data$date1 and data3$date1 where both
listed
You have no date1 only date. Therefore
result<- merge(data, data3, by=c("date", "name"), all=T)
takes all values from both data frames
> dim(data)
[1] 20 15
> dim(d
I think you want something like this (I like to be explicit about what you are
merging)
df3 = merge(df1, df2, by = "date", all=T)
You can be explicit about what you are merging on in each file:
df3 = merge(df1,df2, by.x = "date”, by.y="date", all=T)
You were trying to merge on “date1” but it l
Hello.
Now i tried to do what you told me.
I used the str(fuction), and data$date1 and data3$date1 where both listed
"character". I changed "name" to character but it did not work either.
I also changed all variables to character, with no positive result.
str(data)
'data.frame': 14446 obs. of
>
> Thank you Petr!
>
> I have read on the merge help page, but I cant figure out how to write
this
> function.
> When I use your function it includes all data from "data3", but all
columns
> in "data" has "NA"(without "name" and "date". I hoped to keep these
values
Because name and date comm
The merge function seems perfect for your problem. If you can't get it to work,
the problem may be in the data you are working with, which you have not
supplied (read the posting guide, and use the head and dput functions to make
your example small and reproducible).
One common mistake by beginn
Thank you Petr!
I have read on the merge help page, but I cant figure out how to write this
function.
When I use your function it includes all data from "data3", but all columns
in "data" has "NA"(without "name" and "date". I hoped to keep these values
to.
I try to explain it more precise:
In "d
Hi
> Hello
>
> I am a new user of R and I need help to merge two large datasets about
> stocks with different number of rows and columns.
> Both have 2 variable(column) that are have same values ("name" and
"date1),
> but they are not in same order and "data3" contains much more
observations.
here is some more info:
http://r.789695.n4.nabble.com/file/n3932898/help.jpg
this is what`s happend when I run the function in R
I appreciate if someone can give me some inputs here
Thanks in advance
--
View this message in context:
http://r.789695.n4.nabble.com/merging-two-dataframes-tp393
Hello
I am a new user of R and I need help to merge two large datasets about
stocks with different number of rows and columns.
Both have 2 variable(column) that are have same values ("name" and "date1),
but they are not in same order and "data3" contains much more observations.
In the "data" have
cool. :) yea, the argument names are by.x and by.y, so your by.etc were
ignored in the black hole of "arguments passed to other methods"
on 06/06/2008 09:11 AM Michael Pearmain said the following:
Thanks
Works perfectly.
Was the problem due to me putting by.survey and by.etc rather than by.y
a
try this:
FullData <- merge(ETC, SURVEY, by.x = "ord", by.y = "uid", all.x = T,
all.y = F)
on 06/06/2008 07:30 AM Michael Pearmain said the following:
Hi All,
Newbie question for you all but i have been looking at the archieves and the
help dtuff to get a rough idea of what i want to do
I wo
Hi All,
Newbie question for you all but i have been looking at the archieves and the
help dtuff to get a rough idea of what i want to do
I would like to merge two dataframes together based on a keyed variable in
one dataframe linking to the other dataframe. Only some of the cases will
match but
17 matches
Mail list logo