美文网首页工作生活
R语言for循环练习

R语言for循环练习

作者: ShawnMagic | 来源:发表于2019-07-02 10:21 被阅读0次

Assignment

We obtained the readcount and tpm matrix of miRNA from the results of smallRNA sequencing. But this information was merged in one file, I want to extract the tpm value and divide it into 3 files by tissues.

tissue

  • leaf
  • ovule
  • fiber

Workflow:

import matrix into R ==> select cols of tpm ==> export

code

## import file
miRNA.all<-read.table("~/ShawnProject_PhD/MergedData/Readcount_TPM.xls",
                      header = T,
                      sep = "\t")
str(miRNA.all)
####################################################
# part of the miRNA.all             
# $ B1_O.tpm         : num  86.4 43.2 205.2 17794.9 4697.1 ...
# $ B985S_F.tpm      : num  309 154 0 12748 14098 ...
# $ B985S_L.tpm      : num  1439.1 34.3 34.3 18536.9 445.4 ...
# $ B985S_O.tpm      : num  105.7 26.4 52.8 36069.1 2985.9 ...
# $ B985_F.tpm       : num  422 188 0 27391 12041 ...
# $ B985_L.tpm       : num  902.2 19.2 38.4 21634.6 643.1 ...
# $ B985_O.tpm       : num  176 0 0 23182 4039 ...
####################################################
## the pattern of tpms of each tissue was "_"{tissue}.tpm
# config
seq = c(1,2,3)
tissue = c("F","L","O")
name = c("fiber","leaf","ovule")
# looping
for (i in seq) {
  names <- paste(name[i],".mi",sep = "")
  pattern <- paste("_",tissue[i],".tpm",sep = "")
  assign(names, data.frame(miRNA = miRNA.all$sRNA.readcount,# add the miRNA_id
                           dplyr::select(miRNA.all, contains(pattern))))
}

save(fiber.mi, ovule.mi, leaf.mi, file = "miRNA.tpm.Rdata")

相关文章

  • R语言for循环练习

    for循环在R中很常见也很重要,虽然很简单,但是一定要理解其中的思想。以R语言初级作业第9题为例。加数据加载到R中...

  • R语言for循环练习

    Assignment We obtained the readcount and tpm matrix of mi...

  • R语言for循环①

    for循环是一种重复控制结构,可以让您有效地编写一个需要执行特定次数的循环。 示例: 它产生如下结果: 下标访问 ...

  • R语言 循环

    可能有一种情况,当你需要执行一段代码几次。 通常,顺序执行语句。 首先执行函数中的第一个语句,然后执行第二个语句,...

  • R语言:循环

    这里介绍五种R语言的循环语法,分别是: for if repeat which while for if repe...

  • R语言流程控制

    都知道R语言是向量式编程,可是有时候确实需要用到循环语句,这里就介绍R语言里面的主要循环——for循环。 与其它语...

  • R语言 循环作图

  • R语言-0基础学习4-实战1-常见操作

    R语言学习系列R语言-0基础学习1-数据结构R语言-0基础学习2-构建子集R语言-0基础学习3-循环排序信息处理函...

  • R purrr_ for循环与函数式编程

    for 循环在R中不像其他语言中那么重要,因为R是一门函数式编程的语言。这意味着可以先将for 循环封装在函数里面...

  • C 语言循环练习

    学习C 也有一段时间了,今天做个比较难的练习 练习 思路 1.分析一下,可以把这个图形拆成2个部分,一个正三角形,...

网友评论

    本文标题:R语言for循环练习

    本文链接:https://www.haomeiwen.com/subject/ulnacctx.html