Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

0 rows when merging data.frame in R

$
0
0

Basically every time I try to merge the two data frame I get back a merged data.frame with 0 rows.

The two data frames have different number of rows (one 122 the other 112), different numbers of columns and are are similar to these (data are all invented ndr): df1

S_ID    BMI     WEIGHT  HEIGHT
AA1    18.0   50.0    178
BB2    20.0   60.0    173
CC3    16.0   47.0    170
DD4    23.0   75.0    170

df2

S_ID  sex  age   
AA1    F   20     
BB2    M   27   
CC3    M   26   
DD4    F   18 

As you can imagine, I want to merge them by S_ID. I'm not interested in keeping the rows that are not present in both dataframes. I tried:

  • merge(df1, df2)
  • merge(df1, df2, by = S_ID)
  • merge(df1, df2, by = S_ID, all=FALSE) and even: merge(df1,df2, by = S_ID, all=TRUE) I use RStudio and I directly load the dataset from "import data". The dataset are originally both .csv. When I ask typeof() the two dataset, it says they are list.

UPDATE: Hi everyone, there was precisely an entry issue. In df2 all the names in the column "S_ID" had blank spaces afterwards that I was not aware of. Thank you very much for your help.


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>