a shorter example:
> n <- 4
> x <- data.frame(id=1:n, x1=sample(n), x2=sample(n), s1=1, s2=2, s3=3,
s4=4)
> require(reshape)
> z <- melt(x, id=1:3) # first three columns are ids
> x
id x1 x2 s1 s2 s3 s4
1 1 3 1 1 2 3 4
2 2 4 2 1 2 3 4
3 3 1 4 1 2 3 4
4 4 2 3 1 2 3 4
> x <- data.frame(id=1:100, x1=sample(100), x2=sample(100), s1=1, s2=2,
s3=3, s4=4)
> require(reshape)
> z <- melt(x, id=1:3) # first three columns are ids
> head(z,10) # should be what you want
id x1 x2 variable value
1 1 97 43 s1 1
2 2 89 5 s1 1
3 3 59 97 s1
Hi,
i have to reshape a dataset. my data have the following format:
ID; x1; x2; x3; x4; v1; ... v20
1; 0.1; 0.3; 0.4; 0.2; 2; ... 3
2; 0.3; 0.7; 0.1; 0.2; 1; ... 4
...
999; 0.9; 0.6; 0.3; 0.1; 4; ... 2
1000; 0.2; 0.6; 0.7; 0.8; 1; ... 5
ID is the number of persons (here 1000 persons)
x
3 matches
Mail list logo