silly looping question
1
0
Entering edit mode
nac ▴ 280
@nac-4545
Last seen 9.7 years ago
dear List, Sorry for the silly question, but I am a R beginner and try to sort something out. I have a vector named match containing N positions match=c( "1_880238", "1_883625", "1_1222695", "1_2255524" ,"1_887560") I have a big data frame containing a lot of infos (among those positions in the first column V1 in the same format as in the match vector, example.txt attached ) I want to create an index to pull out only informations in the data frame whose position are the the vector. I have tried this simple loop for (i in match) index=example$V1==i new=example[index,] the new dataframe contain only the last true element...is there a way to get all TRUE ones? thanks Nathalie -- The Wellcome Trust Sanger Institute is operated by Genome Research Limited, a charity registered in England with number 1021457 and a company registered in England with number 2742969, whose registered office is 215 Euston Road, London, NW1 2BE. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: example.txt URL: <https: stat.ethz.ch="" pipermail="" bioconductor="" attachments="" 20111003="" 8afd7dcd="" attachment.txt="">
• 774 views
ADD COMMENT
0
Entering edit mode
@benilton-carvalho-1375
Last seen 4.2 years ago
Brazil/Campinas/UNICAMP
this isn't a BioC question and you'd be better off with the r-help mailing list. what you want is: ids = c( "1_880238", "1_883625", "1_1222695", "1_2255524" ,"1_887560") newdata = example[match(ids, example$V1), ] another approach is newdata = subset(example, V1 %in% ids) best 2011/10/3 Nathalie Conte <nac at="" sanger.ac.uk="">: > dear List, > Sorry for the silly question, but I am a R beginner and try to sort > something out. > I have a vector named match containing N positions > match=c( "1_880238", "1_883625", "1_1222695", "1_2255524" ,"1_887560") > I have a big data frame containing a lot of infos (among those positions in > the first column V1 in the same format as in the match vector, example.txt > attached ) > I want to create an index to pull out only informations in the data frame > whose position are the the vector. > I have tried this simple loop > > for (i in match) > index=example$V1==i > > new=example[index,] > > the new dataframe contain only the last true element...is there a way to get > all TRUE ones? > thanks > Nathalie > > > > > -- > The Wellcome Trust Sanger Institute is operated by Genome Research Limited, > a charity registered in England with number 1021457 and a company registered > in England with number 2742969, whose registered office is 215 Euston Road, > London, NW1 2BE. > "V1" ? ?"V2" ? ?"V3" ? ?"V4" ? ?"V5" ? ?"V6" ? ?"V7" ? ?"V8" ? ?"V9" > ?"V10" ? "V11" > "1" ? ? "1_753405" ? ? ?"1" ? ? 753405 ?"rs61770173" ? ?"C" ? ? "A" ? ? 99 > ? ?0 > "AC=2;DB=3;DP=78;NC=-0.76;CQ=WITHIN_NON_CODING_GENE;AN=2;MQ=29;MZ=6; GN=FAM87B;AD=75;PS=1^1:0.88&2^1:0.30&3^1:0.00;PA=1" > "GT:GQ:DP:FLT" ?"1/1:99:78:0" > "2" ? ? "1_877831" ? ? ?"1" ? ? 877831 ?"rs6672356" ? ? "T" ? ? "C" ? ? 39 > ? ?0 > "AC=2;DB=1;DP=4;NC=0.40;CQ=NON_SYNONYMOUS_CODING;AN=2;MQ=60;MZ=0;GN= SAMD11;AD=4;PS=1^1:1.00&2^1:1.00&3^1:1.00;PA=1" > ? ? "GT:GQ:DP:FLT" ?"1/1:39:4:0" > "3" ? ? "1_880238" ? ? ?"1" ? ? 880238 ?"rs3748592" ? ? "A" ? ? "G" ? ? 42 > ? ?0 > "AC=2;DB=1;DP=5;NC=-3.73;CQ=INTRONIC;AN=2;MQ=55;PA=1^1:0.93&2^1:0.86 &3^1:0.95;MZ=0;PS=1;GN=NOC2L;AD=5" > ?"GT:GQ:DP:FLT" ?"1/1:42:5:0" > "4" ? ? "1_881627" ? ? ?"1" ? ? 881627 ?"rs2272757" ? ? "G" ? ? "A" ? ? 99 > ? ?0 > "AC=2;DB=1;DP=30;NC=2.43;CQ=SYNONYMOUS_CODING;AN=2;MQ=55;PA=1^1:0.72 &2^1:0.00&3^1:0.64;MZ=0;PS=1;GN=NOC2L;AD=30" > ? ? ? ?"GT:GQ:DP:FLT" ?"1/1:99:30:0" > "5" ? ? "1_883625" ? ? ?"1" ? ? 883625 ?"rs4970378" ? ? "A" ? ? "G" ? ? 48 > ? ?0 > "AC=2;DB=1;DP=7;NC=-4.40;CQ=INTRONIC;AN=2;MQ=57;PA=1^1:1.00&2^1:1.00 &3^1:1.00;MZ=0;PS=1;GN=NOC2L;AD=7" > ?"GT:GQ:DP:FLT" ?"1/1:48:7:0" > "6" ? ? "1_887560" ? ? ?"1" ? ? 887560 ?"rs3748595" ? ? "A" ? ? "C" ? ? 99 > ? ?0 > "AC=2;DB=1;DP=67;NC=-2.53;CQ=INTRONIC;AN=2;MQ=58;PA=1^1:0.93&2^1:0.7 5&3^1:0.95;MZ=0;PS=1;GN=NOC2L;AD=66" > ? ? ? ?"GT:GQ:DP:FLT" ?"1/1:99:67:0" > > _______________________________________________ > Bioconductor mailing list > Bioconductor at r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > -- Successful people ask better questions, and as a result, they get better answers. (Tony Robbins)
ADD COMMENT

Login before adding your answer.

Traffic: 587 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6