Entering edit mode
12 months ago
Bioinfonext
▴
470
Hi all,
Here are two data frame list1 has 1483 samples and list2 has 1928 samples. Could you please help how to extract those Sample_ID which are only present in list2 as shown below but not in list1.
list1 <- read.table("phe_nodiab_051223.txt", header=T, sep="\t", a> is=T, na.strings="NA")
> head(list1)
Sample_ID BeadChipID Sentrix_ID Sentrix_Position Batch
1 1.872 200772310035_R08C01 2.00772e+11 R08C01 3
2 1.818 200793300045_R02C01 2.00793e+11 R02C01 20
3 1.492 200788240034_R04C01 2.00788e+11 R04C01 20
4 1.072 200772280022_R08C01 2.00772e+11 R08C01 1
5
> list2 <- read.table("Phe_121023.csv", header=T, sep=",", as.is=T, n> strings="NA")
> head(list2)
Sample_ID BeacChip.ID Sentrix_ID Sentrix_Position Batch
1 1.093 200772280026_R05C01 200772280026 R05C01 16
2 1.095 200772280026_R07C01 200772280026 R07C01 16
3 1.096 200772280026_R08C01 200772280026 R08C01 16
4 1.097 200772280027_R01C01 200772280027 R01C01 16
5 1.098 200772280027_R02C01 200772280027 R02C01 16
6 1.100 200772280027_R04C01 200772280027 R04C01 16
> dim(list2)
[1] 1928 19
> dim(list1)
1483 21
setdiff()
-- from here on make it a learning experience and just try things.thanks a lot, it work very well, what about if I need to extract whole data frame;
Then you use the resulting IDs to subset your original data frame(s).
Instead of
setdiff(list1$Sample_ID, list2$Sample_ID)
do this-setdiff(list1, list2)