This should be simple but for some reason I’m stuck. I have data that looks like
A <- data.frame(x=rnorm(10), y=rnorm(10), z=rnorm(1))
B <- data.frame(x=rnorm(10), y=rnorm(10), z=rnorm(1))
C <- data.frame(x=rnorm(10), y=rnorm(10), z=rnorm(1))
method1 <- list(A=A,B=B,C=C)
method2 <- list(A=A,B=B,C=C)
biglist <- list(method1, method2)
And I’d like to reformat the data to look like
x y z dataset method
- - - --- -----
1 1 1 A 1
1 0 2 A 1
1 0 3 A 1
1 1 3 A 1
1 1 1 B 1
1 0 2 B 1
1 0 3 B 1
1 1 3 B 1
1 1 1 C 1
1 0 2 C 1
1 0 3 C 1
1 1 3 C 1
1 1 1 A 2
1 0 2 A 2
1 0 3 A 2
1 1 3 A 2
1 1 1 B 2
1 0 2 B 2
...
melt doesn’t quite do what I want because it collapses my x/y/z variable headings.
Your data.frames should have a primary key,
e.g., an identifier column, or a column with unique values —
otherwise, you will end up with the x, y, z
coordinates of a point in several unrelated rows.
I will assume that
xis such a column.You may also have to call
dcastaftermelt,if the resulting data.frame is too vertical.