生信星球培训第十一期

学习小组Day5笔记-姜洪利

2018-12-21  本文已影响26人  姜洪利_d076

一、常用包的安装以及工作环境初始配置

此处代码都是引自果子老师的《学习R语言,从这一课开始》,还是留存备用为好。

if(length(getOption("CRAN"))==0) options(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")
if(!require("tidyr")) install.packages("tidyr",update = F,ask = F)
if(!require("dplyr")) install.packages("dplyr",update = F,ask = F)
if(!require("ggplot2")) install.packages("ggplot2",update = F,ask = F)
if(!require("data.table")) install.packages("data.table",update = F,ask = F)
if(!require("ggrepel")) install.packages("ggrepel",update = F,ask = F)
if(!require("devtools")) install.packages("devtools",update = F,ask = F)
if(!require("pheatmap")) install.packages("pheatmap",update = F,ask = F)
if(!require("ggfortify")) install.packages("ggfortify",update = F,ask = F)
if(!require("stringr")) install.packages("stringr",update = F,ask = F)
if(!require("survival")) install.packages("survival",update = F,ask = F)
if(!require("survminer")) install.packages("survminer",update = F,ask = F)
if(!require("glmnet")) install.packages("glmnet",update = F,ask = F)
if(!require("ggpubr")) install.packages("ggpubr",update = F,ask = F)
if(!require("tibble")) install.packages("tibble",update = F,ask = F)
if(!require("cowplot")) install.packages("cowplot",update = F,ask = F)
if(!require("timeROC")) install.packages("timeROC",update = F,ask = F)
if(!require("survivalROC")) install.packages("survivalROC",update = F,ask = F)
if(!require("randomForest")) install.packages("randomForest",update = F,ask = F)
if(!require("Hmisc")) install.packages("Hmisc",update = F,ask = F)
if(!require("jsonlite")) install.packages("jsonlite",update = F,ask = F)
if(!require("ggstatsplot")) install.packages("ggstatsplot",update = F,ask = F)
if(!require("BiocManager")) install.packages("BiocManager",update = F,ask = F)
if(length(getOption("BioC_mirror"))==0) options>     (BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
if(!require("limma")) BiocManager::install("limma",update = F,ask = F)
if(!require("Biobase")) BiocManager::install("Biobase",update = F,ask = F)
if(!require("caret")) install.packages("caret",update = F,ask = F)
if(!require("IRanges")) BiocManager::install("IRanges",update = F,ask = F)
if(!require("DO.db")) BiocManager::install("DO.db",update = F,ask = F)
if(!require("GO.db")) BiocManager::install("GO.db",update = F,ask = F)
if(!require("fgsea")) BiocManager::install("fgsea",update = F,ask = F)
if(!require("clusterProfiler")) BiocManager::install("clusterProfiler",update = F,ask = F)
if(!require("GEOquery")) BiocManager::install("GEOquery",update = F,ask = F)
if(!require("hugene10sttranscriptcluster.db")) BiocManager::install("hugene10sttranscriptcluster.db",update = F,ask = F)
if(!require("DOSE")) BiocManager::install("DOSE",update = F,ask = F)
if(!require("RTCGA.clinical")) BiocManager::install("RTCGA.clinical",update = F,ask = F)
if(!require("bladderbatch")) BiocManager::install("bladderbatch",update = F,ask = F)
if(!require("sva")) BiocManager::install("sva",update = F,ask = F)
if(!require("DESeq2")) BiocManager::install("DESeq2",update = F,ask = F)
if(!require("edgeR")) BiocManager::install("edgeR",update = F,ask = F)

以上包安装完毕之后,先查看工作路径,后根据需要设置自己的工作路径,如下命令:
getwd() setwd() ##get/set workdictionary

二、向量与数据框

R中的数据类型有五种,分别是向量(Vector),矩阵(Matrix),数组(Array),数据框(Data Frame),列表(List);而元素的类型,有数值型、字符型、逻辑型、因子型等。向量是一维的单一类型的元素集合,矩阵是二维的单一类型的元素集合,数组是多维的单一类型的元素集合,数据框是一个二维或多维的元素集合,相当于excel表格,列表是一个虚拟的大容器,什么都可以装。

  1. 向量

向量的提取方法,是在向量后加中括号,其用法引自老师小洁的教程:

x -< rep(1:100, 2)
x[4]
x[-4]
x[2:4]
x[-2:4]
x[c(1, 5)]
x[x == 10]
x[x < 0]
x[x %% 2 ==0]
x[x %in% c(1, 2, 5)]
  1. 数据框

以下引自老师小洁的文章

x[4,]
x[,4]/x[4]
x[4,4]
x[1:4]
x[1:4, 1:4]
x[c(1, 4)]
x[c(1, 4), c(1, 4)]
x$name
  1. attach&with的用法
上一篇下一篇

猜你喜欢

热点阅读