Skip to content
Prev 293623 / 398503 Next

Breaking up a Row in R (transpose)

Hello,


marc212 wrote
Using Petr's Orig data.frame above, maybe this is what you want.

cnames <- unique(colnames(Orig))
nc <- ncol(Orig)/length(cnames)

res <- lapply(seq.int(nrow(Orig)), function(i){
		x <- Orig[i, ]
		dim(x) <- c(length(cnames), nc)
		dimnames(x) <- list(cnames, LETTERS[seq_len(nc)])
		t(x)
	})
names(res) <- rownames(Orig)
res
do.call(cbind, res)

And it avoids loops.

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-Row-in-R-transpose-tp4607658p4609488.html
Sent from the R help mailing list archive at Nabble.com.