Re: [问题] 捞资料

楼主: HeroNoah   2014-08-21 21:00:52
Make anything what you need clean.
reference:
#1JlmgrEG (R_Language)
#1JrRu6ay (R_Language)
x = data.frame(
"gene_a" = c("A", "B", "C"),
"Chromosome" = c("1", "X", "2"),
"gene_start" = as.integer(c(25000, 1000, 0)),
"gene_end" = as.integer(c(50000, 2000, 800)),
stringsAsFactors = FALSE
)
y = data.frame(
"Probe_b" = c("a1", "a2", "a3", "a4", "a5"),
"Chromosome2" = c("2", "4", "1", "X", "1"),
"Chr_s" = as.integer(c(175, 600, 23575, 1010, 30000)),
"Chr_e" = as.integer(c(200, 625, 23600, 1035, 30025)),
stringsAsFactors = FALSE
)
x_merge_y = merge(
x,
y,
by.x = "Chromosome",
by.y = "Chromosome2"
)
condition = (
x_merge_y$gene_start <= x_merge_y$Chr_s
) & (
x_merge_y$Chr_e <= x_merge_y$gene_end
)
output = x_merge_y[condition, c("gene_a", "Probe_b")]
order_index = order(output$gene_a)
output[order_index, ]
作者: celestialgod (天)   2014-08-21 21:35:00
高招,这几篇中,效率最高的方法!

Links booklink

Contact Us: admin [ a t ] ucptt.com