Editing list characters based on column values in a separate list

22 Views Asked by At

I am using iCAMP in R and I have a large list called phylobin which contains information on phylogenetic tree bins and their corresponding ASV ids. In phylobin I have phylobin[["sp.bin"]] and phylobin[["bin.united.sp"]] which contain ASV ids as rownames and bin numbers as columns and a list of all bins and the ids of ASVs they contain, respectively. I want to create a new list of all bins but change out ASV ids for bin.id.new (contained as a col value in phylobin[["bin.united.sp"]]) integer values.

If you are familiar with iCAMP, I want a pdid.bin list.

Here is a snapshot of my data:

> dput(head(phylobin[["sp.bin"]]))
structure(list(bin.id.strict = 1:6, bin.id.united = c(5155L, 
5155L, 5155L, 5155L, 5155L, 5155L), bin.id.new = c(1, 1, 1, 1, 
1, 1)), row.names = c("58280213177cd49ae003f799669083b1", "49da809110cfb2291f15aa751868f909", 
"dda715fd5e83bd6706ccb377023a7b04", "d22c52adf22aaab347d1de64bc394ab4", 
"11e64c80d5ba65bae3e2061c1a71deeb", "ba2e725cf081c898027196308f0b9279"
), class = "data.frame")

> dput(head(phylobin[["bin.united.sp"]]))
list(c("58280213177cd49ae003f799669083b1", "49da809110cfb2291f15aa751868f909", 
"dda715fd5e83bd6706ccb377023a7b04", "d22c52adf22aaab347d1de64bc394ab4", 
"11e64c80d5ba65bae3e2061c1a71deeb", "ba2e725cf081c898027196308f0b9279"))
1

There are 1 best solutions below

0
r2evans On

Perhaps this?

lapply(
  phylobin[["bin.united.sp"]],
  function(z) data.frame(bin = z,
    bin.id.new = phylobin[["sp.bin"]]$bin.id.new[ match(z, rownames(phylobin[["sp.bin"]])) ])
)
# [[1]]
#                                bin bin.id.new
# 1 58280213177cd49ae003f799669083b1          1
# 2 49da809110cfb2291f15aa751868f909          1
# 3 dda715fd5e83bd6706ccb377023a7b04          1
# 4 d22c52adf22aaab347d1de64bc394ab4          1
# 5 11e64c80d5ba65bae3e2061c1a71deeb          1
# 6 ba2e725cf081c898027196308f0b9279          1

(I'm not familiar with pdid.bin formats.)