0

I have a large data set (over 1000 variable), but this is just a small snippet. I am trying to take my original individual ID's from the original data set and create 'fake parents' for each individual. So my FID is my fake data (ending in 3) and the MID is my fake mum (ending in 4). I am now trying to rbind that with the original individual ID's (IID), however, want to do so in the original order of my data, and ensure that the the dad and the mum fall beneath each individual as well.

Here is a snippet of my data:

FID <-

10343
10563
10643
10913
11013
113
etc.

MID <-

10344
10564
10644
10914
11014
114
etc.

IID <-

    10341
    10561
    10641
    10911
    11011
    11012
    111
    112
    etc.

I am trying to bind them to ultimately create a data frame where once they are combined, they are in the correct order in terms of number:

10341
10343
10344
10561
10563
10564
10641
10643
10644
10911
10913
10914
11011
11012
11013
11014
111
112
113
114
etc.

Any help would be great!

Thanks.

Linda
  • 13
  • 1

1 Answers1

0

You can combine all the datasets together and arrange by the value.

library(dplyr)
data <- bind_rows(FID, MID, IID) %>% arrange(col)

In base R :

data <- rbind(FID, MID, IID)
data <- data[order(data$col), ]

Assuming the column name is called col in all the dataframes.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Thanks for you answer! So, I have the first code a go, but got this as a result: `PED <- bind_rows(FID, MID, IID) %>% arrange(FIID) Error: Can't combine `..1$FIID` and `..3$FIID` .` ... Not sure how to fix that? – Linda Mar 31 '21 at 04:10
  • It means the data in all those dataframes have different type. Do all the 3 dataframe have the same column name i.e `FIID` ? Convert all the columns to character, try this : `data <- bind_rows(FID %>% mutate(FIID = as.character(FIID)), MID %>% %>% mutate(FIID = as.character(FIID)), IID %>% %>% mutate(FIID = as.character(FIID))) %>% arrange(FIID)` – Ronak Shah Mar 31 '21 at 04:15
  • This worked! Thank you so much :) – Linda Mar 31 '21 at 07:00