比如原格式文件linear.xlsx是这样的:
VA1和VA2是两个变量,想把它变成以下格式:
则用reshape2包转换:
reshape2
library(openxlsx) library(reshape2) sw<-read.xlsx("E:/linear.xlsx", sheet = 1, colNames = TRUE) da <- melt(sw,id=c("FID","IID"),measure=c("VA1","VA2"))
生成的文件da效果如下: