[R] Pairwise Partitioning of a Vector

From: Gundala Viswanath <gundalav_at_gmail.com>
Date: Mon, 23 Jun 2008 15:13:57 +0900


Hi,

How can I partitioned an example vector like this

> print(myvector)

 [1] 30.9 60.1 70.0 73.0 75.0 83.9 93.1 97.6 98.8 113.9

into the following pairwise partition:

PAIR1
part1 = 30.9
part2 = 60.1 70.0 73.0 75.0 83.9 93.1 97.6 98.8 113.9

PAIR2
part1 = 30.9 60.1
part2 = 70.0 73.0 75.0 83.9 93.1 97.6 98.8 113.9

....

PAIR9
part1 = 30.9 60.1 70.0 73.0 75.0 83.9 93.1 97.6 98.8 part2 = 113.9

I'm stuck with this kind of loop:

__BEGIN__ # gexp is a Vector

process_two_partition <- function(gexp) {

    sort.gexp <- sort(as.matrix(gexp))
    print(sort.gexp)

    for (posb in 1:ncol(gexp)) {

        for (pose in 1:ncol(gexp)) {

          sp_b <- pose+1
          sp_e <- ncol(gexp)

          # This two doesn't do what I want
          part1 <- sort.gexp[posb:pose]
          part2 <- sort.gexp[sp_b:sp_e]

         # we later want to process part1 and part2 separately

        }

    }

}

__END__


R-help_at_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. Received on Mon 23 Jun 2008 - 06:20:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 08:31:01 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive