[R] Cbind warning message

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Oct 16 11:00:11 CEST 2003


Paul Lemmens <P.Lemmens at nici.kun.nl> writes:

> Hello!
> 
> I'm not grasping why cbind (in the code below) warns that
> 
> Warning message:
> number of rows of result
>         is not a multiple of vector length (arg 2) in: cbind(z, p)
> 
> when I do
> 
> sections <- function(length, parts)
> {
> 	p <- 1:parts
> 	q <- length %/% parts
> 	z <- array(p, dim=c(parts,q))
> 
> 	r <- length %% parts
> 	if ( r > 0 )
> 	{
> 		p[r+1:length(p)] <- NA
> 		z <- cbind(z,p)
> 	}
> 
> 	z <- na.omit(as.vector(t(z)))
> }
> 
> and then
> 
> sections(32,5) -> a
> 
> As I see it, rows in result are 5 and the vector length of p (which is
> 5) is a multiple of 5.

Did you intend
   p[(r+1):length(p)] <- NA
?
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list