Question

I have a list of probe ids as below :

> dput(best)
list(c("204639_at", "203440_at", "242136_x_at", "231954_at", 
"208388_at", "205942_s_at", "203510_at", "204639_at"), c("204639_at", 
"203510_at", "231954_at")) 

Then I have used this file:

 > head(sym)
                x
204639_at     ADA
203440_at    CDH2
242876_at    AKT3
207078_at    MED6
208388_at   NR2E3
222161_at NAALAD2

> class(sym)
[1] "data.frame"

Then, I want to find alternative names :

("ADA" "CDH2" "AKT3" "MED6" "NR2E3" "NAALAD2")

In sym and replace existing with elements in "best" file. Does anyone have a hack? Thanks

Was it helpful?

Solution

There is no "hack" needed.

#your data:
best <- list(list(c("204639_at",  "203440_at",   "242136_x_at", "231954_at",   "208388_at", "205942_s_at", "203510_at",   "204639_at" )),
             list(c("204639_at",  "203510_at",   "231954_at")))
sym <- read.table(text="                x
204639_at     ADA
203440_at    CDH2
242876_at    AKT3
207078_at    MED6
208388_at   NR2E3
222161_at NAALAD2", header=TRUE)

#iterate through list and match against sym
rapply(best, function(x) {
  res <- as.character(sym[x,1])
  #omit the following line if you prefer NAs for nomatches
  res[is.na(res)] <- x[is.na(res)]
  res
  }, how="list")

#[[1]]
#[[1]][[1]]
#[1] "ADA"         "CDH2"        "242136_x_at" "231954_at"   "NR2E3"       "205942_s_at" "203510_at"   "ADA"        
#
#
#[[2]]
#[[2]][[1]]
#[1] "ADA"       "203510_at" "231954_at"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top