library(tidyr)
#转长
data <- read.delim("test1.txt")
res1 <- gather(data, AA, value, 2:dim(data)[2], na.rm = T) #宽转长
res <- res1[c(2,1,3)] #调换一列和二列的位置
colnames(res) <- c("colname", "rowname", "value") #随意为三列命名
write.csv(res, "data_long.csv", quote = F)

网友评论