Like this?
x <- structure(list(origin = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
dest = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), ldco = c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), time.slot = c(1L, 2L, 3L,
4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 4L), distortion = c(4.3, 4.7, 5.6, 7.7,
6.8, 7.6, 9.2, 10.7, 2.3, 2.2, 2.6, 4.3, 3.2, 5.4, 4.9, 10.7,
5.6, 8, 7.7, 13.1, 0.3, 2.3, 3, 8.2)), .Names = c("origin",
"dest", "ldco", "time.slot",
"distortion"), class = "data.frame", row.names
= c("1",
"2", "3", "4", "5", "6",
"7", "8", "9", "10", "11",
"12", "13",
"14", "15", "16", "17", "18",
"19", "20", "21", "22", "23",
"24"
))
x[with(x, order(time.slot)), ]
HTH,
Jorge.-
On Wed, Apr 25, 2012 at 11:11 PM, Rebecca < <rebecca0420@yahoo.cn>>
wrote:
>
>
>
>
>
> Hi,
> Here are part of my data,
>
> > pr16.5
> origin dest ldco time.slot distortion
> 1 1 1 1 1 4.3
> 2 1 1 1 2 4.7
> 3 1 1 1 3 5.6
> 4 1 1 1 4 7.7
> 5 1 1 2 1 6.8
> 6 1 1 2 2 7.6
> 7 1 1 2 3 9.2
> 8 1 1 2 4 10.7
> 9 1 1 3 1 2.3
> 10 1 1 3 2 2.2
> 11 1 1 3 3 2.6
> 12 1 1 3 4 4.3
> 13 1 2 1 1 3.2
> 14 1 2 1 2 5.4
> 15 1 2 1 3 4.9
> 16 1 2 1 4 10.7
> 17 1 2 2 1 5.6
> 18 1 2 2 2 8.0
> 19 1 2 2 3 7.7
> 20 1 2 2 4 13.1
> 21 1 2 3 1 0.3
> 22 1 2 3 2 2.3
> 23 1 2 3 3 3.0
> 24 1 2 3 4 8.2
>
> I want to reorder the matrix according to variable time.slot, i.e.
> time slot<- c(1,1,1,1,1,...,2,2,2,2....,3,3,3,3....,4,4,4,4,...)
> Is there any way like a
> Hi,
> Here are part of my data,
>
> > pr16.5
> origin dest ldco time.slot distortion
> 1 1 1 1 1 4.3
> 2 1 1 1 2 4.7
> 3 1 1 1 3 5.6
> 4 1 1 1 4 7.7
> 5 1 1 2 1 6.8
> 6 1 1 2 2 7.6
> 7 1 1 2 3 9.2
> 8 1 1 2 4 10.7
> 9 1 1 3 1 2.3
> 10 1 1 3 2 2.2
> 11 1 1 3 3 2.6
> 12 1 1 3 4 4.3
> 13 1 2 1 1 3.2
> 14 1 2 1 2 5.4
> 15 1 2 1 3 4.9
> 16 1 2 1 4 10.7
> 17 1 2 2 1 5.6
> 18 1 2 2 2 8.0
> 19 1 2 2 3 7.7
> 20 1 2 2 4 13.1
> 21 1 2 3 1 0.3
> 22 1 2 3 2 2.3
> 23 1 2 3 3 3.0
> 24 1 2 3 4 8.2
>
> I want to reorder the matrix according to variable time.slot, i.e.
> time slot<- c(1,1,1,1,1,...,2,2,2,2....,3,3,3,3....,4,4,4,4,...)
> Is there any way like a command or construct a function?
> Thanks!
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org 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.
>
>
[[alternative HTML version deleted]]