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__ - Gundala Viswanath Jakarta - Indonesia
Gundala Viswanath wrote:> 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: >Your code seems strangely out of sync with your example. Why does gexp want to me a matrix and what is the sorting for?? How about lapply(1:9, function(n) {ix <- seq_len(n); list(part1=myvector[ix], part2=myvector[-ix])}) ?> __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__ > > - Gundala Viswanath > Jakarta - Indonesia > > ______________________________________________ > 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. >-- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
One possibility is:
x <- c(30.9, 60.1 , 70.0 , 73.0 , 75.0 , 83.9 , 93.1 , 97.6 , 98.8 ,
113.9)
for (i in 1:9) assign(paste("PAIR",i,sep=""),list(part1 =
x[1:i],part2 = x[-(1:i)]))
--- On Mon, 23/6/08, Gundala Viswanath <gundalav at gmail.com> wrote:
> From: Gundala Viswanath <gundalav at gmail.com>
> Subject: [R] Pairwise Partitioning of a Vector
> To: r-help at stat.math.ethz.ch
> Received: Monday, 23 June, 2008, 4:13 PM
> 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__
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> 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.
Possibly Parallel Threads
- Create a new vector with filled with mean value of original vector
- Data.matrix fail to convert data.frame into matrix
- gamlss results for EXP and LNO seem to have reversed AIC scores
- Error using constrOptim in constraint definition
- Plotting Bi-Gamma Distribution