Re: [R] Rearrange data.

2006-07-19 Thread Gabor Grothendieck
This is FAQ 7.17: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-does-outer_0028_0029-behave-strangely-with-my-function_003f On 7/19/06, Ritwik Sinha <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to rearrange the following data > > d.f <- data.frame(x=c(1,1,2,2), y=c(1,2,1,2), vals=c("a11",

[R] Rearrange data.

2006-07-19 Thread Ritwik Sinha
Hi, I am trying to rearrange the following data d.f <- data.frame(x=c(1,1,2,2), y=c(1,2,1,2), vals=c("a11", "a12", "a21", "a22")) to look like a table with x as the rows and y as the columns, something like y 1 2 x 1a11 a12 2a21 a22 I tried doing this

Re: RE: [R] rearrange data

2005-06-03 Thread jose silva
perfect. thank you Andy! reshape() should do it: > d V1 V2 V3 V4 V5 1 A1 B1 C1 D1 E1 2 A2 B2 C2 D2 E2 3 A3 B3 C3 D3 E3 > d2 <- reshape(d, varying=list(names(d)[1:4]), direction="long")[c(3,1)] > d2[order(d2$V5),] V1 V5 1.1 A1 E1 1.2 B1 E1 1.3 C1 E1 1.4 D1 E1 2.1 A2 E2 2.2 B2 E2 2.

RE: [R] rearrange data

2005-06-03 Thread Liaw, Andy
reshape() should do it: > d V1 V2 V3 V4 V5 1 A1 B1 C1 D1 E1 2 A2 B2 C2 D2 E2 3 A3 B3 C3 D3 E3 > d2 <- reshape(d, varying=list(names(d)[1:4]), direction="long")[c(3,1)] > d2[order(d2$V5),] V1 V5 1.1 A1 E1 1.2 B1 E1 1.3 C1 E1 1.4 D1 E1 2.1 A2 E2 2.2 B2 E2 2.3 C2 E2 2.4 D2 E2 3.1 A3 E3 3.2 B3 E

[R] rearrange data

2005-06-03 Thread jose silva
Dear all: I have this: A1 B1 C1 D1 E1 A2 B2 C2 D2 E2 A3 B3 C3 D3 E3 And I want this A1 E1 B1 E1 C1 E1 D1 E1 A2 E2 B2 E2 C2 E2 D2 E2 A3 E3 B3 E3 C3 E3 D3 E3 Example: m<- matrix(1:15,nrow=3,byrow=T) m v<- unlist(list(t(m[,1:4]))) u<- rep(c(5,10,15),c(4,4,4)) data.frame(v,