library(dplyr) df <- data.frame(z = rep(c("A", "B")), x = 1:6, y = 7:12) %>% arrange(z)
temp <- reshape(df, v.names = c("x", "y"), idvar = c("x", "y"), timevar = "z", direction = "wide") lA <- na.omit(temp[,c("x.A", "y.A")]) lB <- na.omit(temp[,c("x.B", "y.B")]) df.long <- as.data.frame(cbind(lA,lB)) colnames(df.long) <- c("A.x", "A.y", "B.x", "B.y") df.long A.x A.y B.x B.y 1 1 7 2 8 2 3 9 4 10 3 5 11 6 12 Reference: http://blog.wildintellect.com/blog/reshape -- GG [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.