data 처리 작업을 할때 다음과 같이 문자열이 한셀에 그대로 들어가있는 경우가 있다.

또한 행열 전환작업도 같이하고 싶은 상황일때, 12개정도면 엑셀에서도 데이터 처리가 가능하지만 데이터가 많아 질수록 손으로 작업하는것은 업무효율이 낮아진다. 따라서 R을 이용하여 format을 자유롭게 바꿀수 있다.


input file Format




output file Format





if (!require(xlsx)) install.packages('xlsx')
library(xlsx)

proccess.MakeReportForm<- function(fil,Select.count){
# if (is.null(dir)) {
# setwd(dir)
# }
dat <- read.csv(fil,sep = "\t")
colname <- dat[,"Term"]
colname <- as.character(colname[1:Select.count])
genes <- dat[,"Genes"]
genes <- genes[1:Select.count]
Pvalue <<- dat[,"PValue"]
Pvalue <<- Pvalue[1:Select.count]
new_dat <- as.list(NA)

for(count in 1:Select.count){
new_dat <- data.frame(unlist(strsplit(as.character(genes[count]),split = ", ")))
if(count==1){
result <- data.frame(new_dat)
next
}
if (nrow(result) > nrow(new_dat)){
diff <- nrow(result) - nrow(new_dat)
df.na <- matrix(NA, diff, ncol(new_dat))
colnames(df.na)<-colnames(new_dat)
temp <- rbind(new_dat,df.na)
result <- cbind(result, temp)
}else {
diff <- nrow(new_dat) - nrow(result)
df.na <- matrix(NA, diff, ncol(result))
colnames(df.na)<-colnames(result)
temp <- rbind(result,df.na)
result <- cbind(temp, new_dat)
}
}
colnames(result)<-proccess.ColnameFilter(colname)
write.xlsx(result,"result.xlsx",showNA = FALSE,row.names = FALSE)
cat("Finish_ReportForm\n")
}


'R' 카테고리의 다른 글

library(openxlsx) sheet 여러개 쓰기  (0) 2018.11.26
데이터프레임 column 위치(순서) 변경  (0) 2018.11.21
1차 자료형  (0) 2018.11.21
Bioconductor ShortRead  (0) 2018.11.15
scope <<-  (0) 2018.11.09

+ Recent posts