I have two data frames, part of the first data frame BMIis:
Study_No Visit_Date Height Weight BMI KCLfamid outlier year
1 21 2005-05-17 161.0 66.7 25.73 2 0 2005
2 21 1992-06-12 165.0 60.3 22.15 2 0 1992
3 21 2013-05-29 159.0 61.4 24.29 2 0 2013
4 21 2008-07-08 160.5 64.6 25.08 2 0 2008
5 22 1992-06-12 170.0 76.0 26.30 2 0 1992
6 22 2005-05-17 164.0 77.0 28.63 2 0 2005
and the second data frame info822 is:
SampleID KCLfam KCLid DNAextraction DATE_BORN Batch1 plate position
1 21 13 131 2008-11-13 1952-07-25 2 6929806013 R03C01
2 132 13 132 2008-11-13 1952-07-25 2 6929806013 R04C01
3 201 20 201 2006-06-30 1941-01-03 1 6057825005 R05C01
4 202 20 202 2006-06-30 1941-01-04 1 6042308068 R03C02
5 241 24 241 2006-06-30 1925-08-06 1 6057825046 R02C02
6 261 26 261 2005-05-27 1938-11-06 2 6929806023 R05C01
I want to add an new columnDNAextraction inBMI. When the numbers in BMI$Study_No also appear in info822$SampleID , BMI$DNAextraction==info822$DNAextraction, or BMI$DNAextraction=="NA"
So the result what I want to get is like:
Study_No Visit_Date Height Weight BMI KCLfamid outlier year DNAextraction
1 21 2005-05-17 161.0 66.7 25.73 2 0 2005 2008-11-13
2 21 1992-06-12 165.0 60.3 22.15 2 0 1992 2008-11-13
3 21 2013-05-29 159.0 61.4 24.29 2 0 2013 2008-11-13
4 21 2008-07-08 160.5 64.6 25.08 2 0 2008 2008-11-13
5 22 1992-06-12 170.0 76.0 26.30 2 0 1992 NA
6 22 2005-05-17 164.0 77.0 28.63 2 0 2005 NA
Is it correct that use for loop and if/else statement to answer this question?
Aucun commentaire:
Enregistrer un commentaire