100天生信-Day6
长数据和宽数据是满足不同分析的两种数据格式,可以很方便用R的reshape2包转换,代码如下:
library(reshape2)
## long -> wide
setwd("PATH")
long <- read.csv("long.csv" , header = T)
colnames(long)
wide <- dcast(long, Gene_name ~ Cis_element)
write.csv(wide,'wide.csv',row.names = FALSE)
## wide -> long
setwd("PATH")
wide <- read.csv("wide.csv" , header = T)
colnames(wide)
long = melt(wide, id=c("Primer"),
variable.name= 'FR', value.name = 'Seq')
write.csv(long,'long.csv',row.names = FALSE)