如何去掉“”对象名称和循环工作?
我不知道如何准确定义这个问题;但我无法弄清楚这一点,
genx <- list(scaffold_1 = c("AAATTTTTATAT"),scaffold_2 = c("AAATTTTTATAT"),
scaffold_3 = c("AAATTTTTATAT"),scaffold_4 = c("AAATTTTTATAT"),
scaffold_5 = c("AAATTTTTATATA"),scaffold_6 = c("AAATTTTTATAT"),
scaffold_7 = c("AAATTTTTATAT"),scaffold_8 = c("AAATTTTTATATA"))
TATA = "TATA"
myobs <- paste("genx$scaffold_", 1:8, sep = "")
我想将以下函数应用于 myobs 元素(是对象)的每个元素:
source("http://www.bioconductor.org/biocLite.R")
biocLite("Biostrings")
require((Biostrings)
countPattern (TATA, genx$scaffold_1, max.mismatch = 1)
[1] 3
当我使用以下内容时:
countPattern (TATA, myobs[1], max.mismatch = 1)
不起作用,因为我相信解释为:
countPattern (TATA, "genx$scaffold_1", max.mismatch = 1)
[1] 0
与上面不同一。如何摆脱“”并创建一个循环来执行这项工作,感谢您的建议:
I do not know how to precisely define this problem; but I could not figure this out
genx <- list(scaffold_1 = c("AAATTTTTATAT"),scaffold_2 = c("AAATTTTTATAT"),
scaffold_3 = c("AAATTTTTATAT"),scaffold_4 = c("AAATTTTTATAT"),
scaffold_5 = c("AAATTTTTATATA"),scaffold_6 = c("AAATTTTTATAT"),
scaffold_7 = c("AAATTTTTATAT"),scaffold_8 = c("AAATTTTTATATA"))
TATA = "TATA"
myobs <- paste("genx$scaffold_", 1:8, sep = "")
I want to apply the following function to every elments of the elements of myobs (are objects):
source("http://www.bioconductor.org/biocLite.R")
biocLite("Biostrings")
require((Biostrings)
countPattern (TATA, genx$scaffold_1, max.mismatch = 1)
[1] 3
When I use the following:
countPattern (TATA, myobs[1], max.mismatch = 1)
Doesnot work as it is I believe interpreted as:
countPattern (TATA, "genx$scaffold_1", max.mismatch = 1)
[1] 0
Which is not same as the above one. How can get rid of "" and create a loop to perform this job, your suggestions are appreciated:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以直接使用列表并执行
sapply
操作,该操作作用于列表的每个元素。这是一些示例代码You can directly use the list and do an
sapply
which acts on every element of the list. Here is some sample code您可以使用
get
函数You can use the
get
function这个怎么样:
What about this:
有一个问题:
因为 R 认为您正在寻找具有该全名的对象,而不是“genx”的“scaffold_1”组件。
应该有效的是:
但是请参阅:
更多的麻烦点可以在“The R Inferno”中找到:http://www.burns-stat.com/pages/Tutor/R_inferno.pdf
There is a problem with:
because R thinks you are looking for an object with that full name, not the 'scaffold_1' component of 'genx'.
What should work is:
But see:
More trouble spots along these lines can be found in 'The R Inferno': http://www.burns-stat.com/pages/Tutor/R_inferno.pdf
我建议您将 genx$scaffold 定义为向量,然后您可以轻松使用 apply 函数:
现在您可以轻松地在每个 genx$ 上运行
countPattern()
函数脚手架的元素您可以轻松扩展解决方案,以便 genx$scaffold 也可以是矩阵等。
I would recommend that you define
genx$scaffold
as vector, and then you can easily use the apply function:Now you can easily run the
countPattern()
function on every genx$scaffold's elementYou can easily extend the solution so that genx$scaffold can be also matrix etc.