1. java环境配置
2. R包安装
#方法一
source("http://bioconductor.org/biocLite.R")
biocLite("kernlab")
#方法二
install.packages("kernlab")
#方法三
if(!suppressWarnings(require('kernlab')))
{
install.packages('kernlab')
require('kernlab')
}
#方法四(推荐)
library(BiocManager)
BiocManager::install("plot3D",ask = F,update = F)
3. R包卸载/卸除/查看加载
#卸载
remove.packages("rlang")
remove. packages(c("pkg1","pkg2") , lib = file .path("path", "to", "library"))
#卸除:在包使用函数冲突,检验函数依赖时比较有用
detach("package:RMySQL")
#已加载
(.packages())
4. Rstudio设置
(1)ctrl+Alt+Shift+0 显示四个窗口
(2)R版本共存
- https://segmentfault.com/a/1190000015332215?utm_source=tag-newest
- https://blog.csdn.net/ChenQihome9/article/details/81949965
- https://cran.r-project.org/bin/windows/base/old/
5. 文件读取
- (1)读写excel
library(readxl)
data<-read_xlsx('E:/代码/机器学习/winequality-red.xlsx', sheet = 'Sheet1')
library(openxlsx)
data<-read.xlsx('E:/代码/机器学习/winequality-red.xlsx')
#install.packages("rJava")
#install.packages("xlsx")
#Sys.setenv(JAVA_HOME='C:/Program Files/Java/jdk1.8.0_171/jre')
library(rJava)
library(xlsxjars)
library(xlsx)
data<-read.xlsx(workbook, 1, encoding='UTF-8') #name sheet 防乱码
write.xlsx(BP, paste('GO_BP_Module_', i, '.xlsx', sep=""), row.names = F)
write.xlsx(BP, 'target_GO_BP.xlsx')
- (2)读写txt
data<-read.table(file.choose(),header=T, sep="\t")
6. 常用数据处理函数/代码
-
参考:https://www.cnblogs.com/zongfa/p/8537031.html (dplyr、tidyr包)
-
多向量取交集
A<-c()
B<-c()
C<-c()
result<-Reduce(intersect, list(A, B, C))
- 横向输出
library(tidyr)
data<-as.data.frame(t(data)) #任意向量
colnames(data)<-c(1:dim(data)[2])
result<-unite(data,"combine",colnames(data), sep="\t", remove = F)[,1] #combine可改,、\t空格间隔
- 拆分填充行
#excel 初步处理得到互作对
ncRDeath<- read.table(file.choose(),sep = "\t", stringsAsFactors = F,header = T, fill=TRUE, quote = "")
head(ncRDeath)
ncRDeath2<-ncRDeath[ncRDeath$Gene_Symbol != "" & ncRDeath$miRBase_mature_ID != "",]
final<-data.frame()
for (i in 1:dim(ncRDeath2)[1]){
#i=1
ncR_break<-data.frame(miRBase_mature_ID=unlist(strsplit(ncRDeath2[i,1], ",")),Gene_Symbol=ncRDeath2[i,2])
final<-rbind(final,ncR_break)
print(i)
}
dim(ncRDeath2) #2119
write.table(final,"6-ncRdeathDB_miRNA_break.txt",row.names = F,quote = F,sep="\t")
- 重置和变换
#(1)重置变量名
library(reshape)
rename(ncrdeathDB_miRNA, miRBase_mature_ID="miRNA", Gene_Symbol="target_mRNA")
#(2)重置数据框
inputData<-data.frame(cats[, c (2,3)], response = as.factor(cats$Sex))
#(3)正确添加表头:将行名加入矩阵
datamatrix= cbind(rownames(datamatrix),datamatrix)
rownames(datamatrix)[1]<-'A'
7. 清除所有变量
rm(list = ls())
8. 计算运行时间
exeTimeTsne<-system.time(tsne)
9. 平台对接
- (1)与SPSS对接
setwd('')
#install.packages('foreign')
library(foreign)
data.spss<-read.spss("car_sales.sav", to.data.frame = TRUE)
head(data.spss)
#install.packages('Hmisc')
library(Hmisc)
mydataframe<-spss.get("C:/Users/Administrator/Desktop/test.sav", use.value.lables=TRUE)
- (2)与python对接(不成功)
参考: - https://www.jianshu.com/p/06dbd8dcc198
- https://stackoverflow.com/questions/59321283/reticulate-py-available-returns-false
#install.packages("reticulate")
library(reticulate)
网友评论