Hi everyone.
I want to transpose a data frame. Lets say the following DF:
df = data.frame(matrix(ncol=4, nrow = 10))
df[,1] = c(rep(1,5),rep(2,5))
df[,2] = c(rep('a',4),rep('b',3),rep('c',3))
df[,3] = c(letters[5:14])
df[,4] = runif(10)
I would like to form a data frame with each line corresponding to colon X1
and create a variable with columns X2 and X3.
This would give me a DF with the following columns.
/
*X1, ae, af, ag, bi, bj, bk, cl, cm, cn*
/1 n n n n n NA NA NA NA NA
2 NA NA NA NA NA n n n n n
where n = numbers in column X4.
I'm not sure how to manipulate my DF to rearrange it so I keep var X1 but I
create 10 new variables with coloumns X2 and X3 with values from X4.
I hope I have been clear enough!
Thank in advance for your insights,
Phil
--
View this message in context:
http://r.789695.n4.nabble.com/Matrix-transposition-tp4599219.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
[email protected] mailing list
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.