From: Berwin A Turlach <berwin_at_maths.uwa.edu.au>

Date: Sun 05 Feb 2006 - 20:14:12 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Feb 05 20:24:56 2006

Date: Sun 05 Feb 2006 - 20:14:12 EST

>>>>> "BAT" == Berwin A Turlach <berwin@maths.uwa.edu.au> writes:

>>>>> "TM" == Taka Matzmoto <sell_mirage_ne@hotmail.com> writes:

TM> and then assign the character vector to the numeric vector by

TM> names<-first.10 TM> first.10 = numeric.vector TM> combined.one <- cbind(names,first.10) TM> container <- diag(10) TM> for (i in 1:(10*10)) BAT> I don't really understand this loop. If I reverse-engineer this codeBAT> correctly thenthe matrix `combined.one' is not a 2*100 matrix, so you BAT> should get an error while exectuting this loop. This should have been: ... `combined.one' is not a 100*2 matrix ...

TM> Is there any other neat way to do this? BAT> Neat way to create those character vectors? Or a neat way to read in BAT> the data from a file?

BAT> If the latter, I would use the following code: Before somebody else points out the obvious optimisation of my code, here is a (slightly) improved version of the function

matzmoto <- function(file, diag=TRUE){ dat <- scan(file) nn <- nvar <- sqrt(2*length(dat)+0.25) - 0.5 if(!diag){ nvar <- nvar + 1 } res <- matrix(0,nvar,nvar) ind <- upper.tri(res, diag=diag) rind <- 1:5 while(nn > 0){ if( nn < 5 ){ rind <- rind[1:nn] } how.many <- sum(ind[rind,]) res[rind,][ind[rind,]] <- dat[1:how.many] dat <- dat[-(1:how.many)] rind <- rind + 5 nn <- nn - 5 } t(res) }

Cheers,

Berwin

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Feb 05 20:24:56 2006

*
This archive was generated by hypermail 2.1.8
: Mon 06 Feb 2006 - 04:03:36 EST
*