How to do a Vlookup-type function using a value range
2
0
Entering edit mode
Elena Sorokin ▴ 150
@elena-sorokin-4659
Last seen 9.6 years ago
I have two data frames as input: > small Position 1 6 2 14 3 1 > lookup_table Start Stop Value 1 1 5 a 2 6 10 b 3 11 15 c And I want the following output: > outcome Position Value 1 6 b 2 14 c 3 1 a What is some R code that I can write to accomplish this task? Thank you, Elena [[alternative HTML version deleted]]
• 966 views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 50 minutes ago
United States
Hi Elena, Why does 14 return c? Best, Jim On Tuesday, May 06, 2014 3:34:41 PM, Elena Sorokin wrote: > I have two data frames as input: > >> small Position > 1 6 > 2 14 > 3 1 > > >> lookup_table Start Stop Value > 1 1 5 a > 2 6 10 b > 3 11 15 c > > And I want the following output: > >> outcome Position Value > 1 6 b > 2 14 c > 3 1 a > > What is some R code that I can write to accomplish this task? > > Thank you, > > Elena > > [[alternative HTML version deleted]] > > _______________________________________________ > 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 -- James W. MacDonald, M.S. Biostatistician University of Washington Environmental and Occupational Health Sciences 4225 Roosevelt Way NE, # 100 Seattle WA 98105-6099
ADD COMMENT
0
Entering edit mode
Use findOverlaps from GenomicRanges. On Tue, May 6, 2014 at 4:06 PM, James W. MacDonald <jmacdon@uw.edu> wrote: > Hi Elena, > > Why does 14 return c? > > Best, > > Jim > > > > On Tuesday, May 06, 2014 3:34:41 PM, Elena Sorokin wrote: > >> I have two data frames as input: >> >> small Position >>> >> 1 6 >> 2 14 >> 3 1 >> >> >> lookup_table Start Stop Value >>> >> 1 1 5 a >> 2 6 10 b >> 3 11 15 c >> >> And I want the following output: >> >> outcome Position Value >>> >> 1 6 b >> 2 14 c >> 3 1 a >> >> What is some R code that I can write to accomplish this task? >> >> Thank you, >> >> Elena >> >> [[alternative HTML version deleted]] >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor@r-project.org >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane. >> science.biology.informatics.conductor >> > > -- > James W. MacDonald, M.S. > Biostatistician > University of Washington > Environmental and Occupational Health Sciences > 4225 Roosevelt Way NE, # 100 > Seattle WA 98105-6099 > > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane. > science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
@harris-a-jaffee-3972
Last seen 9.5 years ago
United States
If X and Y are your data frames, the rows you want are given by library(IRanges) nearest(IRanges(X[,"Position"], width=1), IRanges(start=Y[,"Start"], end=Y[,"Stop"])) On May 6, 2014, at 3:34 PM, Elena Sorokin wrote: > I have two data frames as input: > >> small Position > 1 6 > 2 14 > 3 1 > > >> lookup_table Start Stop Value > 1 1 5 a > 2 6 10 b > 3 11 15 c > > And I want the following output: > >> outcome Position Value > 1 6 b > 2 14 c > 3 1 a > > What is some R code that I can write to accomplish this task? > > Thank you, > > Elena > > [[alternative HTML version deleted]] > > _______________________________________________ > 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
ADD COMMENT

Login before adding your answer.

Traffic: 1099 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