-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre_plot.R
More file actions
42 lines (41 loc) · 1.35 KB
/
Copy pathpre_plot.R
File metadata and controls
42 lines (41 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
pre_plot<-function(datasets,col,group="NA",col.name="NA"){
##merge mutil dataset to a dataframe to plot
##datasets:a list of all dataset
##col:a list about datasets colnames, the order must corresponding with datasets
##group:a vector that group the final datasets
##col.name:new colname, must set, if don't set when colname set to 1:ncol(data)
datalist<-list()
if (group!="NA") {
for (i in 1:length(datasets)) {
datalist[[i]]<-datasets[[i]][,col[[i]]]
datalist[[i]][,"group"]<-group[i]
if (col.name!="NA") {
colnames(datalist[[i]])<-col.name
}else{
colnames(datalist[[i]])<-paste("V",1:ncol(datalist[[i]]),sep = "")
}
}
}else if (length(names(datalist)!=0)) {
for (i in 1:length(datasets)) {
datalist[[i]]<-datasets[[i]][,col[[i]]]
datalist[[i]][,"group"]<-names(datasets)[i]
if (col.name=="NA") {
colnames(datalist[[i]])<-paste("V",1:ncol(datalist[[i]]),sep = "")
}else{
colnames(datalist[[i]])<-col.name
}
}
}else{
for (i in 1:length(datasets)) {
datalist[[i]]<-datasets[[i]][,col[[i]]]
datalist[[i]][,"group"]<-i
if (col.name=="NA") {
colnames(datalist[[i]])<-paste("V",1:ncol(datalist[[i]]),sep = "")
}else{
colnames(datalist[[i]])<-col.name
}
}
}
data<-Reduce(rbind,datalist)
return(data)
}