0

I am trying to merge two data frames. One data frame, which we'll call "Final" is much longer than the second data frame, which is called "Indvi". I will take a screen shot of the dataframes for reference:

"Final" dataframe

"Indvi" dataframe

When I did try the merge function, I get a dataframe where "Final" is shown first but then when "Indvi" is shown, all the rows are filled with NS values.

This is the R code I used for merge, which gave the NA values:

finaldf<- merge(DDMfinal, DDMindvi1, by="subject", all.x = T)

I would like the merge to be aligned by the subject ID. There is a column for that in each dataframe.

As for possible problems/source of issue, nothing is wrong with the "by=" because there is a subject column in each dataframe and I set all.x to TRUE. So I really dont know why its giving me issues.

This is what my merge product looks like:

Incorrect merge output

Any help as to why this is happening and how to fix it would be much appreciated!! Thank you so mcuh!

PS: Im sorry for all the pictures, I refered to the "How to ask a good question" post but they only talked about how to not place CODE in pictures and they didnt say anything on how to place dataframes. So, I settelted in pictures, :), sorry if it is inconvenient.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • 1
    Hi Kim! the best way for you to share your dataframes is by leaving into your question the output of `dput(head(YOUR_DATAFRAME))`. So that other users are able to run your code. Pictures are useful for graphs or when you need a visual aid – Edo Sep 22 '20 at 08:06
  • 1
    Usually data is often confidential or too large to share with `dput`. You may want to take a minute and get familiar on [how-to-make-a-great-r-reproducible-example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) on Stack Overflow. Often the issue solves itself automatically then ;) – jay.sf Sep 22 '20 at 09:30

0 Answers0