美文网首页
R中不时用到的小函数

R中不时用到的小函数

作者: yingyonghui | 来源:发表于2020-05-21 09:47 被阅读0次

    grep 查询某一pattern在字符串向量中出现的位置

    > haystack <- c("red", "blue", "green", "blue", "green forest")
    > grep("r", haystack)
    [1] 1 3 5
    

    grepl 同grep,返回T或F

    > haystack <- c("red", "blue", "green", "blue", "green forest")
    > grepl("r", haystack)
    [1]  TRUE FALSE  TRUE FALSE  TRUE
    

    melt函数

    reshape2::melt(time_cell,varnames=c('Time','Celltype'),value.name="number")
    

    sub替换字符串

    rownames(doublet.score) <- sub(pattern='\\-1$',replacement='',x=rownames(doublet.score))
    

    gsub同sub,但sub仅替换匹配到的第一个pattern,gsub替换所有匹配的pattern

    map values

    Time <- plyr::mapvalues(Time, from=c('T0','T1','T3','T7','T14'), to=c('0','1','3','7','14'))
    

    tiff格式画图

    tiff(file="xxx.tiff",height=500,width=600,res=100,compression="lzw")
    
    dev.off()
    

    保存变量

    #保存某几个变量
    save(mergedMEs, mergedLabels, mergedColors, file="WGCNA.RData")
    #保存全部变量
    save.image(file="file.RData")
    

    相关文章

      网友评论

          本文标题:R中不时用到的小函数

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